I have to extract specific data from mail body

mail body will be like —

List value 1…(PR).
ABCD 990 yu delete 90
CBGB 556 Yu delete 80
.
.
.
----End----------------------------------

sss open 67 value (PR).

----End----------------------------------

List value 2…(PR)
ABCD 990 yu delete 90
CBGB 556 Yu delete 80
.
.
.
----End----------------------------------
sss open 67 value (PR).

----End----------------------------------

From this mail body I have to extract data which is in between List value 1 and End and List value 2 and End.

Please suggest me any regex or any other method to extract it.

Thank you so much.

Hi @Mohini_Gupta

I played around and found one solution. It is slightly less elegant than I would like to, but works nonetheless.

See the attached workflow and let me know if you have any questions:
SplittingStrings.zip (2.8 KB)

It uses a simple .Split method twice to get the result. It then iterates through all results by using an index. The try catch is there to handle the situation when there are no more results found (if someone knows a more elegant solution to solve the Outside of Index issue, I’d love to see it).

1 Like

It might be cleaner if you use a For Each, then you don’t need to detect the end of the list.
Here is an alternate way using a mixture of Regex and string manipulation:
Main2.xaml (7.0 KB)
There’s gotta be a way with Regex.Matches or even Regex.Split but I couldn’t get a pattern working with it (as I’m not an expert), so I took a slightly different approach by Replacing the matched lines then splitting.
@Mohini_Gupta

Regards.

1 Like

Yes, I tried with For Each but then it would iterate through the last Split function and not the middle one (which seems to control the actual, good output).

I got it to run with Regex on regex101.com but only with the flag
U
that seems to not be supported by Matches activity.

If there is a way to set a flag in code, it would be the best solution.

1 Like

Hi ,
In the mail body length will be changing for every mail or it will be default.If it is not changing then u can directly take the substring u will get the output

1 Like

@Mohini_Gupta
Nevermind, I got it working with Regex :slight_smile:

See following example:
SplittingStrings.zip (2.3 KB)

The regex looks like that:
(?=List value).*?(?<=----End----------------------------------)

The flags that must be set on the Matches activity:
image

I think it is the most elegant solution.

1 Like