I have about 5000+ lines in a csv file. Part of each line looks like this:

...Name 1:, Smith, John, Name 1 #:...

...Name 1:, Doe, Jane, Name 1 #:...

I need a regex that will remove the comma between last and first name so it looks like this:

...Name 1:, Smith John, Name 1 #:...

...Name 1:, Doe Jane, Name 1 #:...

I have tried every example I could find on Google and Superuser.com

I have gotten as far as being able to select the name with the comma in it with:

(?<=Name 1:,).*?(?=, Name 1 #)

I am assuming I will need to limit everything down to the characters between "Name 1:," and "Name 1 #:" then select the comma and replace the string excluding the comma.

However this is where I am stuck.


I'd do something like

Find: Name 1:,(.+),(.+), Name 1 #

Replace: Name1:,\1\2, Name1 #

The parentheses capture the last name and the first name. The \1 and \2 in the replacement string refer back to those captures.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.