I have a love-hate with RegEx. I acknowledge the power it has, but can't seem to crack this particular task. I am given a variety of formats for names and need to parse out and rejoin first and last only.
Here's my expression: ^(\w+)\W?((?<=\W).+(?=\W))?\W?(\w+)?$
The only things I can't figure out are hyphenated last names and apostrophes.
Here's my data: The "Full Name" column is my input and the rest are the output of my RegEx parse.
edit: My "Data" is just filler in a variety of first and last names. The actual names are all over the place and my company wouldn't allow be to share that data. I created 9 variations that I've seen in the actual data.
| Full Name | First Name | Middle Name | Last Name |
| First Last | First | | Last |
| First Middle Last | First | Middle | Last |
| First Last-Last | First | Last | Last |
| First O'Last | First | O | Last |
| First Middle Middle Last | First | Middle Middle | Last |
| First Middle Last-Last | First | Middle Last | Last |
| First O'last-Last | First | O'last | Last |
| First Middle O'Last | First | Middle O | Last |
| First M Last | First | M | Last |
I know that the answer is likely in one of the hundred posts on this topic, but I just can't find it! Is anyone able to help?
Thanks!