How to extract just some parts of an Outlook mail

howto
uipath
selection
substring

#1

Hi guys!

Hope you all doing well.

I have a doubt and I would like you to help me.

I’m trying to extract two adresses from an email. The Inbox receives the e-mail in a standard model, just like that:

Address 1: Rua Jose Augusto Rodrigues 174

District:Moema

City:sao paulo - sp

zip code: 99837464

Retrieve time:08:00 to 08:00 pm

A/C:John

The two addresses are just like the above standard on the e-mail body.

I’m already using the get mail outlook message activity to read the body.

Specifically, I need to record in the variables, the string from “Address 1” until “John” in str_adr1 and the second address in str_adr2.

Anyone has any idea of how can I do it?

Thanks in advance,

Renan Maciel


#2

Hello,

You can use the regular expression for this, there is search option to check the start and end of matching result so try regEx.

Thanks,
Meg


#3

Hi Megharaj,

Thanks for the help.

I’m new at uiPath programming and still not understand how works the syntax of regex.

Could you please show me how it works?

Thanks in advance.

Renan Maciel


#4

Hello,

Is the john word is fixed?
if so try the below regex, it works.

^Address([a-zA-Z\s\S]*?)John$

Test it here: https://regex101.com/r/tFf434/2

Thanks,
Meg


#5

Hello Meg,

Thanks for your help.

But if you could, I still need your help.

I’m already saving the e-mail body into a variable.

After using the regEx formula, I need to save the result into another variable and paste it into a field in the ERP.

Below, is the information that I need to record into the address variable.

Do you have any idea of how can I do it inside the uiPath using the Assign activity?

Thanks in advance Meg,

Renan Maciel


#6

Hi @renanmaciel

The syntax for the Assign activity would look like that:

yourNewVariable = System.Text.RegularExpressions.Regex.Match(yourOldVariable,"Retrieval address:([a-zA-Z\s\S]*?)^\s*\n").ToString

This will Assign the result of the Regex search to a new variable.


#7

Hi @loginerror

Thanks for your help!

I used your syntax adapted to my project, but it still not worked, I used a message box to show the result of the Regex based on the body of the e-mail and it returns a blank message as if mail body was empty…

Do you have any idea of the reason that it occurs?

If necessary, I can share my project for easy analysis.

Thanks in advance.


#8

I updated the Regex a bit, hopefully it still fits your needs (same output, different boundary condition):
https://regex101.com/r/Ynk4Wc/1

System.Text.RegularExpressions.Regex.Match(inputString,"(?<=Retrieval address: ).+?(?=Pick up address:)",RegexOptions.Singleline).Tostring

Refer to the attached workflow for to see it in action :slight_smile:
RegexSearch.zip (2.3 KB)


#9

Hello @loginerror!

It worked.

Thank you very much for your help! :smiley: :grin:


#10

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.