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

Question

Question

How to use conditional and pattern matching together

asked on June 25, 2015

I have a document class that I'm using pattern matching to pull the date from. The date can appear one of two ways:

Passed and Approved this 6th day of May, 2015

or 

Passed, Adopted and Approved this 6th day of May 2015.

I want QuickFields to run the first pattern match. Then run a conditional process if the first pattern match returned an empty token run the second patter match. 

I've got all that setup what I don't know is how to get the tokens combined as one result and what to put in the metadata field? 

Any suggestions? 

0 0

Replies

replied on June 25, 2015

You can do that but you don't really need to. You can make the comma optional in your first pattern by adding a "?" after it to indicate "0 or 1".

0 0
replied on June 25, 2015

Thank you Miruna, how do I make the whole word "adopted" optional? 

0 0
replied on June 26, 2015

You can try the following expression:

\w*\,?.*

That would put either value in the token.

0 0
replied on July 2, 2015

Sorry for the late reply. Try this:

Passed(?:, Adopted)? and Approved this (\d\d?)..(\s)day of (.+),(.+)

It returns 6 May 2015 for both examples above.

(?: text) is a non-capturing group construct for pattern matching and the ? after indicates it may or may not be there.

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

Sign in to reply to this post.