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

Question

Question

Forms - Regular Expression Question

asked on March 28, 2017

I have a field in Forms that a user types in the Last Name, First Name Middle Initial.  

My current Regular Expression is (\w+,)\s(\w+)\s(.)

There are instances where the employee has a hyphenated last name or no middle name.  

For example, Smith-Lock, Joe T or Smith, Joe

I'm looking for an expression that would handle all four data entries below:

Smith, Joe T  or  Smith-Lock, Joe T  or  Smith-Lock, Joe   or   Smith, Joe 

Thanks for any ideas!

Pete

0 0

Answer

APPROVED ANSWER
replied on March 28, 2017

Hi Pete, you might try:

([\w\-]+,)\s(\w+)(\s(.))?

Where [\w\-]+ is "at least one word character or hyphen" (note that the hyphen character itself needs to be escaped with the backslash) and (\s(.))? indicates that the last section corresponding to a middle initial is optional.

1 0
replied on March 29, 2017

Hi James,

That worked!  Thank you for the assistance.

0 0
replied on April 12, 2017

Hi James, 

I have another question.

I have a token in workflow that I apply a regular expression to.   

My current Regular Expression is (\w+)\s?(\w*)\s

There are instances where the value, for example, is   Lake, Pete W  or  Lake-Jones, Pete W  or  Lake-Jones, Pete    or    Lake, Pete

My expression works except for when the value is Lake, Pete .  It will not show the first name. 

Thanks for any ideas!

Pete

0 0
replied on April 12, 2017

I'm not seeing that behavior. (\w+)\s?(\w*)\s returns "Pete" for "Lake, Pete W" and "Lake-Jones, Pete W" and nothing for "Lake-Jones, Pete and "Lake, Pete". This is expected behavior since it does not account for the comma or the dash in the hyphenated last names.

Side note: This regex is set to extract data (the parentheses are match groups, anything outside of them will not be returned), so if it worked, you'd get the name with no spaces. Is that the intent?

0 0
replied on April 12, 2017

Hi Miruna,

The intent of this Regular Expression is to return the First Name only when the value is:  

Lake, Pete W or 

Lake-Jones, Pete W or

Lake-Jones, Pete  or

Lake, Pete

The above examples are the four different values populated in the field.  

How would I modify my Regular Expression to return "Pete" for "Lake-Jones, Pete" and "Lake, Pete"? 

 

0 0
replied on April 12, 2017

[\w\-]+,\s?(\w+)

Are we assuming people will not have hyphenated first names?

1 0
replied on April 12, 2017

That is correct!

0 0

Replies

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

Sign in to reply to this post.