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

Question

Question

Pattern Matching On Multiple Lines of Text

asked on December 6, 2017

I need some help with a pattern match that involves returning multiple lines of text.  Here is one example of text

 

You Sold :
AMCAP FUND CLASS F-1  Trade Date:
Process Date:
Settlement Date:
Cusip:
Symbol:AMPFX
 

The text that I need returned is AMCAP FUND CLASS F-1.  I created  a pattern match that captures everything before Trade Date and I used (.*)  [Trade Date:] and this gave me the desired result until I came across this 2nd example

You Bought :
BGF GLOBAL MULTI ASSET INCOME FUND CLASS D2 (USD)
(OFFSHORE)  Trade Date:
Process Date:
Settlement Date:
Cusip:

 

In this case I would need to capture BGF GLOBAL MULTI ASSET INCOME FUND CLASS D2 (USD)
(OFFSHORE).  My regular expression would need to identify everything before Trade Date and the previous line, or I would need a regular expression that can identify everything in between You Bought: or You Sold: and Trade Date:, but I am not sure how to do a pattern match spans multiple lines of text.

 

Thanks!

0 0

Answer

SELECTED ANSWER
replied on December 6, 2017 Show version history

This should work for both examples.

.*\n(.*)\n?(.*)Trade Date:

I ran it through Pattern Matching in Workflow and used your example text and was able to produce what you are looking for.

0 0
replied on December 7, 2017

Thanks! I gave this a try and it worked!

0 0

Replies

replied on December 6, 2017

You will probably want to try using something like the following:

(.*)\s*\n?\s*[Trade Date:]

I added in the \s* which will accommodate if there are any spaces. The \n looks if there is a new line character. If that doesn't work, try \r which looks if there is a return character. The new line and return characters are hidden characters, so you can't tell if they are there just by looking at them. The ? after the \n tells it it may exist or it may not. That way if everything is on one line it should still work. If there is not a new line or return character I'm not sure.

0 0
replied on December 6, 2017

Hi Jeff, no expert at Regex but you could also try these.

(?s)You Sold :(.*)Trade Date

(?s)You Bought :(.*)Trade Date

In this matter you'd have two pattern matching tokens so you would require a conditional logic in your workflow to pick the one that contains data or combine them into a single field as one result will be blank using the token calculator.

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

Sign in to reply to this post.