Lori Ansell
Lori Ansell

Reputation: 11

Extracting FirstName from Last, First Middle

I am trying to figure out a regular expression for extracting just the first name from Last, First Middle

For example: Smith, Jane Ann returns just Jane.

I figured out the last name field by using ^[a-zA-Z_'^\s]+.

I believe I want the first name extracted by grabbing the first word after the comma, but I'm at a loss as to how to do that. Also, these are two separate fields, so the first name needs to be singled out.

[^,]*$ gives me both first and middle names

/(?<=, ).*(?=) also gives me both first and middle names

Upvotes: 1

Views: 202

Answers (1)

Barmar
Barmar

Reputation: 780889

Use the lookbehind to match the comma, and follow that with a more specific pattern that matches non-whitespace characters, so it won't include the middle name.

(?<=, )\S+

Upvotes: 1

Related Questions