I need to fetch 8 characters from Merchant Code column from mail body, how can i do it?
Hi @Mayur_N
Could you try the below one,
(?<=Queries\s)[A-Za-z]+
- Assign -> Output = System.Text.RegularExpressions.Regex.Match(VariableName.toString,"(?<=Queries\s)[A-Za-z]+").Value
Pass the Variable in the place of VariableName.
Hope it helps!!
No, It is not working.
I need to fetch that JZpTukoW (8 character string) in the column of Merchant Code.
-
Get IMAP Mail Messages (or Get Outlook Mail Messages)
- Output: mailMessages (List)
-
For Each mailMessage in mailMessages
a. Assign
- emailBody = mailMessage.Bodyb. Matches
- Input: emailBody
- Pattern: (?<=Merchant Code: ).{8}
- Result: matches (MatchCollection)c. For Each match in matches
i. Assign (or Print)
- merchantCode = match.ToString()
Could you share me the mail body in a text format… @Mayur_N
Then it’s possible to write the regex for that.
If you want regex for 8 characters check the below one,
[A-Za-z]{8}
Hope you understand!!
To extract data, such as a “Merchant Code,” from an email body in UiPath, you can follow these steps:
- Use a Get Mail activity to retrieve the emails and save them to a variable.
- Iterate through the emails using a For Each activity with the Type Argument set to
System.Net.Mail.MailMessage. - Inside the loop, use an Assign activity to get the body of the email as a string (e.g.,
mailBody = item.Body.ToString). - If the “Merchant Code” follows a consistent pattern, you can use string manipulation methods like
IndexOf()andSubstring()to extract it. For example:
If mailBody.Contains("Merchant Code:") Then
Dim startIndex As Integer = mailBody.IndexOf("Merchant Code:") + "Merchant Code:".Length
Dim endIndex As Integer = mailBody.IndexOf(Environment.NewLine, startIndex)
Dim merchantCode As String = mailBody.Substring(startIndex, endIndex - startIndex).Trim()
End If
- If the email body is in HTML format and the data is in a table, you might need to convert the HTML to text or use an HTML parser to extract the table data.
Hi @Mayur_N ,
You can do this as below
Workflow:
- Assign1: It Will remove the new line from mail body
System.Text.RegularExpressions.Regex.Replace(mail.Body, "\r\n", " ")
- Assign2: It will remove the extra spaces from words
System.Text.RegularExpressions.Regex.Replace(Mail_body.Trim, "\s+", " ")
- Regex to extract the Merchat Code
System.Text.RegularExpressions.Regex.match(Mail_body.Trim, "(?<=Queries\s)(.*?)[\s]").ToString.Trim
Output:

Hope it helps you ![]()
Regards,
Vinit Mhatre

