cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Reg exp query

I have a email library. When the email is received SP reads the email body and stores the email text in a column. The whole of the email body text is pulled but I only need the first few sentences. How do set up a reg ex to only extract text from the email body up to a certain word.

0 Kudos
Reply
14 Replies
Workflow Hero

Re: Reg exp query

When you say a certain word, do you mean a given word, such as received?

Then this should do it

^.*received

If you mean 5 words, then this would do it

^(\w+\b\s+){5}

but it doesn't take into account any punctuation characters

This interactive site is brilliant for testing out regexs https://regexr.com/

Note, don't use IE, chrome or firefox work just fine

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Reg exp query

Let me add some details for my query.  So the emails received into the library are emails that advise that the email was undeliverable to a list of people. I want to pull out this list people (their email address) into a column.

Example: The blue boxes are the email addresses.

There is lots of text after this part of the email body which I do not need.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Reg exp query

It looks like you want to capture anything that looks like an email address from the message body

This regex tester site https://www.regextester.com/19 has a pre-filled regex that appears to do exactly what you want - it matches emails and ignores any other text

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Reg exp query

Thanks Graham

This is what I need. The only thing is under the text showed above is the  

Diagnostic information for administrators: which contains all the emails address the email was sent too. I only need the failed ones in the to part of the email.  If there was a why to only pull the top part of the text this would then work. 

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Reg exp query

That sounds straight-forward - the first recipe I showed would allow you to retrieve everything before Diagnostic

^.*Diagnostic

Then pull out the emails that are in the resulting string

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Reg exp query

Thanks graham lattin 

What operation do I need to use?

I can't get this to work. Are you able to send a screen shot?

Thanks

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Reg exp query

I don't have a screenshot to share

assume BodyStr holds the email body

the first regex task would take BodyStr and extract everything up to Diagnostic into TempStr

a second regex task would then process TempStr to extract the emails and place the results into a collection

I had a quick play but it only seems to get the first email address - also, I amended the regex slightly to not match the text up to the string end (ie remove the trailing $)

^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*

The issue might be that it cannot do a multiline extract, in which case there should be a previous step that replaces returns with blanks

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Reg exp query

OK, Ive had a little more time ot look at it this morning

The problem was that it cannot cope with multiline strings, so here goes

1 select everything before Diagnostic into TempStr

2 replace all the line breaks with a space (find [\r\n]+)

3 capture all the remaining email addresses into a collection using the Extract option - ignore the fixed to start and end of string markers:

[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*

I used the log history to output the collection and got all of the emails I expected

I hope this helps

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Reg exp query

I can't get ^.*Diagnostic part to work.

Workflow Details

Error in regular expression action. parsing "*(?=Diagnostic)" - Quantifier {x,y} following nothing
0 Kudos
Accept as Solution Reply