0

I regularly need to process large lists of user data for our marketing emails. I get a lot of CSVs with full name and email address and need to split these full names into separate first name and last name values. for example:

John Smith,jsmith@gmail.com

Jane E Smith,jane-smith@example.com

Jeff B. SMith,jeff_b@demo.com 

Joel K smith,joelK@demo.org 

Mary Jane Smith,mjs@demo.co.uk

In all of these cases, I want Smith to go in the last name column and everything else into the first name column. Basically, I'd like to look for the last space before the first comma and replace that last space with a comma. But, I'm lost on how to do this, so any suggestions would be greatly appreciated. Also, I'm using BBEdit to process the text file.

Pruthvi Raj
  • 3,016
  • 2
  • 22
  • 36
John Egan
  • 225
  • 1
  • 11
  • My favorite article ever: [Falsehoods Programmers Believe About Names](http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names) – Sam Sep 04 '15 at 17:54

1 Answers1

0

Try the following regex:

(.*?) (\b\w*\b)(,[^,]*$)

And the substitution:

$1,$2$3

DEMO

After substitution, the data will be as follows:

John,Smith,jsmith@gmail.com

Jane E,Smith,jane-smith@example.com

Jeff B.,SMith,jeff_b@demo.com

Joel K,smith,joelK@demo.org

Mary Jane,Smith,mjs@demo.co.uk
Pruthvi Raj
  • 3,016
  • 2
  • 22
  • 36