How to extract dynamic text from weekly email

Hi all - I am a citizen developer and new to UiPath. I’ve completed the basic trainings. I want to extract specific text from an email whose contents changes every week, but will always have the building name contained in the text string that i want.

For example, i want to only extract all of the text regarding Skytower below:

  • Walnut plaza 12/13/23 event to be discussed
  • Skytower 12/04/23 big event with 200 people
  • Skytower 12/13/2023 chairs and tables for 630 people and the CEO
  • Skytower tables and desks
  • Hickory Plaza 12/12 ice cream social

Use Regex in the Find Matching Patterns activity:


The Result will be an ienumerable of all matches.


Hi @michael_j_brady

1. Get Outlook Mail Messages
2. For Each Email in MailMessages
    3. Assign: extractedText = System.Text.RegularExpressions.Regex.Match(Email.Body, "Skytower[^\r\n]*").Value
    4. Log Message: "Extracted Text: " + extractedText

Hope it helps!!

Hello @michael_j_brady

You can learn more about regex from my Megapost :slight_smile:



Hi @michael_j_brady

=> Use Get Outlook Mail Messages to retrieve the messages and store the output in a variable.
=> Run a For Each loop to iterate through list (MailMessages) variable.
=> Inside the loop, use assign activity and give below syntax:

str_Body= CurrentMail.Body.ToString

=> Use the below syntax in another assign activity:

text= System.Text.RegularExpressions.Regex.Matches(str_Body,"Skytower(.*)")

OutputDataType is IEnumerable(System.Text.RegularExpressions.Match)

=> Run a For Each loop for text variable and print the message using Log Message.

Hope it helps!!

It’s not necessary to assign to separate variables (str_Body and text). Just do…


…in the “In” property of the For Each.

Hi @michael_j_brady

Can you try this

System.Text.RegularExpressions.Regex.Match(emailBody, “(?m)^(.Skytower.)$”).Value