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

Question

Question

Need some help with a regular expression

asked on May 9, 2019

I have a Document name = LastName FirstName MiddleName I need to populate three matching fields in a Laserfiche template.  So far using workflow Assign Token vales I have been able to parse out the LastName using \w+  I am having a problem finding a way to parse out FirstName then MiddleNmae.  I have searched with Google and have not been able to find what I am looking for.  Could use some assistance.

Thanks

John

 

0 0

Answer

SELECTED ANSWER
replied on May 9, 2019 Show version history

You can try something like this

Note how the FullName token parses the entry name, but the other 3 tokens parse the previous FullName token.

The Regular Expression text:

  1. FullName = ^([^_]+)
  2. LastName = ^([^\s]+)
  3. FirstName = ^[^\s]+\s+([^\s]+)
  4. MiddleName = ([^\s]+)$

 

These expressions all assume that the name has 3 parts and no part has a space.

If you have a name like "Van Damme Jean Claude" or "Miller David Eldon Robert", the patterns will not work.

2 0

Replies

replied on May 9, 2019

Is the Middle always followed by the Underscore?

 

You can start by getting just the name

FullName patern = ^([^_]+)

The above pattern grabs everything from the start of the input until it gets to an "_"

Then use the FullName token as the input for your other patterns.

1 0
replied on May 9, 2019

Oh that is good, gonna have to put that in my box of tricks. 

0 0
replied on May 9, 2019

Hi Travis there must be some misunderstanding We have the LastName and the First Name figured out it is the middle name I need assistance with Example

Doe John William_1

want it to return William.      \S+$ returns William_1 with the above example.  Need to loose the _1

0 0
replied on May 9, 2019

Hello Jim,

 

In my other reply, I suggested you could use this:

 

([a-zA-Z]+)_?\d?$

 

This would get the middle name but would only work if the middle name only contained letters (So would not work on hyphenated names)

 

The example that Bert has supplied I feel is more elegant as it would clean up the input, and then you can use \S+$ to get the middle name. 

 

Regards,

Travis 

0 0
SELECTED ANSWER
replied on May 9, 2019 Show version history

You can try something like this

Note how the FullName token parses the entry name, but the other 3 tokens parse the previous FullName token.

The Regular Expression text:

  1. FullName = ^([^_]+)
  2. LastName = ^([^\s]+)
  3. FirstName = ^[^\s]+\s+([^\s]+)
  4. MiddleName = ([^\s]+)$

 

These expressions all assume that the name has 3 parts and no part has a space.

If you have a name like "Van Damme Jean Claude" or "Miller David Eldon Robert", the patterns will not work.

2 0
replied on May 10, 2019

Thanks Bert that worked great.  I can do simple things with regular expressions but when it comes to more complicated things I am lost.  Thanks again for all your help.

John

0 0
replied on May 9, 2019 Show version history

Try this:

Using \S+ will return things like full hyphenated last names, where \w+ will only return the part of the name before the hyphen.

0 0
replied on May 9, 2019

FirstName \s+[\S+]  only returns first character of first name

0 0
replied on May 9, 2019

John - 

Those characters are parentheses, not brackets:

\s+(\S+)

0 0
replied on May 9, 2019

Hi Jim is there anything I can add to the MiddleName regular expression that would disregard the _1 or anything that would follow?

Doe John William_1

Return: William

0 0
replied on May 9, 2019

([a-zA-Z]+)_?\d?$

That should work for both

 

Doe John William_1

and

Doe John William

0 0
replied on May 9, 2019

That works great I have one more request after the middle name it is followed by :Example

Doe John William_1 I would like to remove anything that follows the middle name.

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

Sign in to reply to this post.