Oh no! The Community appears to be haunted! Help us find all the spooky specters here.
We are currently experiencing an issue with Email verification at this time and working towards a solution. Should you encounter this issue, please click on the "Send Verification Button" a second time and the request should go through. If the issue still persists for you, please email support@alteryx.com for assistance.

Alteryx Designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
SOLVED

RegEX Question - Name Parsing

JohnMaty
9 - Comet

HI  All,

I have example names here:

 

Kinsel-Davis, Elijah Sulaiman
Kinsel, Elijah S

Arrington, Melanie

 

I am trying to parse these into LastName, FirstName, Middle Name using RegEx.

 

I use this (^.+),(.+) and it works to break out the last and first name, but when I try to bring out the middle name, which can be absent, a single letter or a full name, I get odd returns.  How do I account for a full name, a letter or blank with regex?

 

(^.+),(.+)?\s(.\>) does not work

 

Any help would be great

 

 

 

 

7 REPLIES 7
andre347
10 - Fireball

You could do something like: .+,\s(\w+) to get the middle name. This reads: find any character up to a comma (,) then a white space (\s) then a group which will be the middle name.

MarqueeCrew
19 - Altair
19 - Altair

@JohnMaty,

 

Here's what I did:

 

(.*),\s{0,1}(.*)\s(.*)

Capture.png

 

Cheers,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
Please Subscribe to my youTube channel.
JohnMaty
9 - Comet

Why is melanie in as a middle name and not a first name?

MarqueeCrew
19 - Altair
19 - Altair

@JohnMaty,

 

Reasonable question.

 

How about:

(.*),\s{0,1}(\w+)\s*(.*)
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
Please Subscribe to my youTube channel.
JohnMaty
9 - Comet

If you have a moment, I would really love to know in plain english how this works.  What does each segment do?

 

I took the regex class at Inspire this year and was good with it but forgot some of it due to lack of use.  Thanks in advance.

 

MarqueeCrew
19 - Altair
19 - Altair

@JohnMaty,

 

 

 

 
(.*),\s{0,1}(\w+)\s*(.*)
Using Mark's English:
 
The first group marked by a parenthesis is anything UNTIL a comma followed by zero or 1 space character.
The second group is one or more word characters, usually letters for names, followed by zero or more spaces.
The third group is whatever comes after the second group omitting those spaces.
 
Cheers,
Mark
 
 
 
1st Capturing Group 
(.*)
 
.*  -   matches any character (except for line terminators)
 
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
, matches the character , literally (case sensitive)
 
\s{0,1}
 matches any whitespace character (equal to [\r\n\t\f\v ])
{0,1} Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
 
2nd Capturing Group 
(\w+)
 
\w+
 matches any word character (equal to [a-zA-Z0-9_])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
 
\s*
 matches any whitespace character (equal to [\r\n\t\f\v ])
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
 
3rd Capturing Group 
(.*)
 
.*
 matches any character (except for line terminators)
 
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
Please Subscribe to my youTube channel.
JohnMaty
9 - Comet

Awesome.  Thanks for the insight.  Leave to the Alteryx community to always step it up!

 

Labels