0

I need to run advanced find and replace using regex. I have a CSV similar to the following:

"Item 1a,,,,
,,Item 1b,,,,
,,Item 1c"
"Item 2a,,,,
,,Item 2b,,,,"

I need to remove the trailing commas for lines that start with a " quote. I can match the correct lines like so:

(".*?),,,,$

The problem is, that selects the entire row, rather than just the trailing commas.

Anybody know how to match this correctly? so that only the commas are matched, on lines that start with " quote.

0

1 Answer 1

1

You are already capturing the content before the commas, just put it all back using a back reference in the replace:

Search: ^(".*?),+$
Replace: $1

Note: You need to anchor you regex to start of line ^ to match a quote there (otherwise it will match a quote anywhere in the line).

Sign up to request clarification or add additional context in comments.

2 Comments

@hwnd but he doesn't want to highlight, he wants to replace the commas with blank to remove them. From OP's question: I need to run advanced find and replace using regex ... to remove the trailing commas for lines that start with a ". OP thinks he has to match only the commas, but this is a solution that works.
I get that, it is replacing (only selecting the commas): regex101.com/r/aQ4sI6/2 Bohemian is correct, it's too easy to just backreference the captured group in the replacement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.