[SOLVED] How to extract value from raw HTML body

Hello,
Please if someone can help. On the picture below, you can see my simple workflow. So I’m getting an unread message from my inbox and I’m extracting email body (HTML) correctly.

Now I need to extract some data from HTML body but not sure how. so what I need to extract is shown in bold. Is there a possibility to extract from string with StartsWith and EndsWith? if yes how.

Thanks in advance!

<![endif]–>

<td style="font-size:0;padding:10px 25px;word-break:break-word"align=center>
Transaction ID: 362, User ID: 266144, SKU: paypal-gc-usd-20
 
<!–[if mso | IE]>

Regex statements are your best option for this. You can use the Matches Activity to help.

An example to find the transaction ID would be:

(?<=Transaction ID: )(.*)(?=, User ID)

1 Like

Ok, this seems to be working but now when I have regex value, I would like to convert it to String @ronanpeter do you know how to do that? I tried for each item in regex collection and convert items to string but it’s not working … do you know what could be wrong and is there any other method?

Thanks in advance

@ivanhorvat83
In case of you want to get prepared for multiple matches:

  • flattened in to one string: string.Join(",",MatchActivityOutputVar)

Getting the matches individually use

  • for each activity, Type: Match
  • then use item.toString

In case you want to rely that you will get only a single match:

  • matches.First.ToString

Verify that System.Text.RegularExpressions is imported

@ppr I did what you wrote and I get this …

Also if I do without “First” than I don’t have compiler error but i don’t get anything from regular expression. I checked several times regular expression and I’m able to get positive results so regex is working fine.

Found the bug — my regex should look like this (?<=Transaction ID: )(.*)(?=, User ID) but UiPAth is not recognizing it as valid regex - : is part of HTML code which is inserted into body … Do you know how to write this and make regex valid?

My html code looks like this: - `

Transaction ID:& # x 20;362, User ID:& # x 20;266144, SKU:& # x 20;paypal-gc-usd-20

Spaces in between & # x 20 are not exisitng i just entered to avaoid formatting from this page text editor
`

In any regex online tester/editor it works fine, in UiPath it’s not working correctly :frowning:

Ok, I’m stupid … forgot to put regex into " " … sorry …

Thanks, guys @ppr and @ronanpeter you helped me a lot!!!

Best regards!!!

@ivanhorvat83
Please Verify that System.Text.RegularExpressions is imported

otherwise the first Statement could fail