Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
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
20 - Arcturus
20 - Arcturus

@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 restart. 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
20 - Arcturus
20 - Arcturus

@JohnMaty,

 

Reasonable question.

 

How about:

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

Chaos reigns within. Repent, reflect and restart. 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
20 - Arcturus
20 - Arcturus

@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 restart. 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