Regular Expression to get LastName / FirstName from a text

Viewed 71

I've a text file like :

67890                    LastName, FirstName                                                                          
09/10/2020 18:18:01                               Page 1 of 1
DOB    01/01/1982     38 years         Male
..........

I would to extract LastName, First Name separately, then with 2 regexp to grab:

  • LastName as all the Chars before the first comma "," removing spaces before it.
  • FirstName as all the chars after the first comma "," removing spaces after it.

I did a test for the LastName with (C#):

^.*?(?=,)

but is grabbing all before the comma , not just the LastName.

Also the Code :

(?<=^.{20})([^,])+

is grabbing 20 chars before the comma but includes the Spaces. I Would just grab all chars before comma, could also be 20 chars before comma not to include the initial numbers.

I'm using the Test Site :

http://regexstorm.net/tester

Many Thanks for help!

1 Answers
Related