You are viewing limited content. For full access, please sign in.

Question

Question

Split Full Name using Expression

asked on August 18, 2021

Hi, can someone tell me what expression I can use to split this name format? I would like extract the Last Name then the First Name then Middle Initial. I have LastName field, FirstName field and MiddleInitial field

Deer, John Moe

Also more IMPORTANTLY, I do want to understand/learn how the expression works. How did someone come up with the expression.

 

 

0 0

Replies

replied on August 19, 2021

While parsing names is almost never the suggested course of action, it sometimes is the only option you have. I tried to add some common variations that occur into the regular expressions that might cause slip-ups.

 

Last Name - ([\w\-\s]+),

This code will filter out the part of the string before the comma. The capture group (Open and closed parentheses) will return only the value inside of it if it finds a match. The comma at the end will be used in matching, but will not end up in the Last Name token since it is outside of the capture group. The character class is marked by the square brackets, this allows you to specify multiple different characters to be used in any order.

\w is any word character. Basically A-Z and 0-9.

\- matches hyphens literally. This would allow hyphenated last names.

\s is white space characters. You may see people with names like Smith III, John A

The + symbol allows the character class to be matched one or more times. Similarly you might see *, but that is zero or more times.

 

 

That part is relatively straight forward. The hard part is knowing what constitutes peoples' first and middle names. You kind of have to just pick a way of doing it here. I'm going to go with the assumption that most people have a first name that is one word, maybe hyphenated.

First Name - ,\s([\w\-]+)

Similar to the last name code, the capture group will come after a single comma, and then a single white space character. I removed the white space from the character class, as I only want it to match the first word.

 

Middle Initial - ,\s[\w\-]+\s(\w)

Removing the capture group from the first name field, I added another space, and then grabbed the next word character.

 

 

All this being said, pattern matching text in this manner will almost never work 100% of the time. Naming conventions vary massively. People might have two first names, no middle names, multiple middle names, and so on. 

I will also say that I am by no means a RegEx expert. The code above is almost certainly not as optimized/clean as it could be. I would recommend loading up regex101.com, loading in some sample data that you are trying to parse, and playing around with it. Its a pretty neat website that has helped me out a ton in the past.

2 0
replied on August 19, 2021

Hello,
On the name it is presumed that:
the LastName always ends in comman (,)
and the MiddleInitial is always a single word (not compound) at the end of the name
My proposal using workflow functions would be:

1.- Name = 'Deer, John Moe'
2.- LastName = %(Name#@Split(/,);Trim@##[1]#)
3.- MiddleInitial = %(Name#@Split( );Trim@##[-1]#)
4.- FirstName = %(Name#@Split(/,);Split(%(MiddleInitial));Trim@##[2]#)
 

 

1 0
replied on August 19, 2021

Orighty then, so long with the coding you gave a explanation. I now understand piece by piece. Very well APPRECIATE IT!!!!

0 0
replied on August 19, 2021

Oh WOW, i just ran into that Zscaler Directory Authentication  regex101.com. AWESOME tool to learn with TOO!!!   Thank Youuuuuu!!!!

0 0
replied on August 19, 2021

All Sweet!!! Another way to skin a cat. Keep it coming. I want options!!!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.