How to extract specific words under a Header with Regex or else

I have a sequence where i sort incoming emails.

Ill use Get Outlook Mail Message and get a variable (mailList)

Now i want to sort out the emails with certain words in the Subject line and in the Mailbody

the word inte the subject line is “SEABN” and it will always be in the subject line.
The words i look for in the mail body is “UPDATE” (thats the header) and then “Added Individuals” and/or “Deleted Individuals”

i have tried this:
(?<=UPDATE\s)\w*

And that worked to get the first word after/under the Header (UPDATE) But how do i get the word in the second row under the header.

The mail body looks like this: And its always looks like this.

Dear colleagues,

Please find the updated ABN attached.

UPDATE

Added individual. SER#7-9 added to ABN

The rules for the body text:

Action implemented = Added individual. AND Information altered = SER#7-9 added to ABN.
eg: Added individual. SER#7-9 added to ABN.
Action implemented and Information altered are always separated by a dot/period.

Actions can be some of these:
• Added individual
• Deleted individual (Not Departed)
• Reason for Deletion
• Change in International Travel Itinerary
• Change in Domestic Itinerary
• Change in Escort Information

Please advise
Milo

Hi @Milo_Soderberg

For getting the second row Try with \n

Example → (?<=UPDATE\s)(\S.+)\n\S.+

Regards
Gokul

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=UPDATE\r?\n\r?\n)[\w ]+").Value

Regards,

Thanks Gokul and Yoichi,

i havent had time to try your suggestions. I will do it tomorrow.

i have one more question
How can i save all lines under the header (UPDATE) so i can use it further down the process (write it in an excel file)

please advise

Hi,

an you try the following expression? If need to store each line in excel row by row, please split it by linebreak.

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=UPDATE\r?\n[\s\S]+").Value

Regards,

Hi,

This one worked well. thank you!
Ive got Added Individual from the body.

Dear colleagues,

Please find the updated ABN attached.

UPDATE

Added individual. SER#7-9 added to ABN

System.Text.RegularExpressions.Regex.Match(yourString,“(?<=UPDATE\r?\n[\s\S]+”).Value
this one didnt work instantly. ive got this error msg.

fel.medd.regex.docx (480.2 KB)

Can you please elaborate how i can save line by line.
linebreak= after \r?

regards
Milo

Hi,

Sorry, the above lacked ) . Can you try the following?

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=UPDATE\r?\n)[\s\S]+").Value

Regards,

thanks for the swift reply

ive got this error msg.

Value cannot be null…docx (475.4 KB)

/Milo

Hi,

Is there some white space after UPDATE? If so, the following might be better.

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=UPDATE)[\s\S]+").Value

OR

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=UPDATE)[\s\S]+").Value.Trim

Regards,

Hi,

No there isnt.

The rules for the body text:

Action implemented = Added individual. AND Information altered = SER#7-9 added to ABN.
eg: Added individual. SER#7-9 added to ABN.
Action implemented and Information altered are always separated by a dot/period.

Actions can be some of these:

UPDATE
Added individual
Deleted individual (Not Departed)
Reason for Deletion
Change in International Travel Itinerary
Change in Domestic Itinerary
Change in Escort Information

all of these actions will not appear at the same time. But perhaps 2-3 of them.

/Mil0

Hi,

If possible, can you share your text as a text file and expected output?

Regards,

Hi,

here is the textfile you asked for.

mailfor regex.txt (602 Bytes)

Output is something i can use to write in the excelfile that ill pass on to the Performer.
either if the information is written in another excelfile (Because the excelfile for the performer is not made yet in my process) were i can transfer it.

Or in a datatable or array of string.
im not sure which is the best here.

please advise.