I am working with patient data and am parsing a 'Patient Name' column out using RegEx. The name column is structured as followed:
LastName FirstName MiddleName/Initial(sometimes) Suffix (sometimes)
Note: There are never any commas separating Last Name from First Name.
Examples:
Smith John B
Doe Jane
Smith John Brian Jr
Doe Jane Kate
My current RegEx works if there is a Middle Name or Middle Initial present, but will not work if a Middle Name/Initial is lacking. Can someone help make the expression dynamic to work even if there is no Middle Name/Initial? Below is my current expression:
(\w+)\s(\w+)\s(\w*)
Thanks for your help.
P.S. I know this can be done with a Text To Columns tool, but am trying to become more familiar with the RegEx tool.
Solved! Go to Solution.
HEy @kaca226_ ,
I just tested your expression and it is working as it should. Are you looking for a regular expression where you have a suffix but not a middle name/initial? For that you would need a list of suffix I think.
Best,
Fernando Vizcaino
Hey @fmvizcaino
The expression works if there are trailing spaces after the ending name in Field1. So in your screenshot, if you add a Data Cleansing tool first to remove trailing spaces, the expression wouldn't parse out row #2. I was able to modify the expression in order to fix this issue. See below:
(\w+)\s(\w+)\s*(\w*)
I added the underlined * after the second \s, which appears to work. Thank you for your reply!

