How we can extract the text from mail body in the below format

want to extract 1100,2000,2200 this from the below mail and want a output in this format (1100,2000,2200) -

mail Body - Dear User,

A master data request 7773 has been approved. A Material Master 1012014 ( Benzoic Acid Flakes ) has been created.

  1. Click here-> 7773 (New material code - Benzoic acid Flakes) to log into MDG system.

Change Request Details:

Material Type:ROH(Raw materials)

Plant Details:
Plant Plant Desc
1100 P01
2000 M-3
2200 W-67

Regards,
MDG Team

Please Help me

Hi @Ajinya_jorwekar

You can try the below regular expression to extract the required output,

(?<=Plant[\s\S]+)\d{4}

Hope it helps!!

But I want Output in this format (1100,2000,2200)
How i get output like this - (1100,2000,2200)

Okay @Ajinya_jorwekar

Store the Mail body in a variable called Mail_Body.

- Assign -> Output = String.Join(",", System.Text.RegularExpressions.Regex.Matches(Mail_Body.toString, "(?<=Plant[\s\S]+)\d{4}"))

Check the below image for better understanding,

Hope it helps!!

Thanks @mkankatala
it gives me expected output, But in same type of mail it extract other 4 digit values also, but i only want output Plant (3500,4800) it below mail body

it gives other 4 digit also but i only want (3500,4800)

Mail body - "Dear User,

A master data request 7663 has been approved. A Material Master 40210213303323 ( Galsoft EcoCare 145H 200KG 9.4TWTDRUMLP ) has been created.

  1. Click here-> 7663 (New Material code create to Galsoft EcoCare 145H 200kg pack) to log into MDG system.

Change Request Details:

Material Type:FERT(Finished Product)

Plant Details:
Plant Plant Desc
3500 MAERSK WAREHOUSE
4800 URAN WAREHOUSE

Storage Locations:
Plant Code Storage Locations Storage Locations Desc
3500 3595 WM Storage Locat
4800 4890 Non-WM Storage L
4800 4895 WM Storage Locat

Warehouse Details:
Warehouse No. Warehouse Desc
350 Bhiwandi Maersk Warehouse
480 Uran Warehouse

Regards,
MDG Team
"

Please help me to extract only 3500, 4800 from above string

Okay got it @Ajinya_jorwekar

Then you can try the below regular expression,

- Assign -> Output = String.Join(",", System.Text.RegularExpressions.Regex.Matches(Mail_Body.toString, "(?<=Plant Details:[\s\S]+)(?<!\s\d+\s)\d{4}(?=\s[A-Z]+)"))

Check the below image for better understanding,

Hope it helps!!

Check in the below images it was working for both mail body’s… @Ajinya_jorwekar

Thank you so much @vrdabberu @mkankatala

Thanks for sharing but this could optimzed or dynamic ragex

Absolutely! Here’s the optimized regular expression for extracting the plant numbers from the email body:

Code snippet(?<plantNumber>\d{4}) (?=P\d{2}|M-\d|W-\d)

Explanation:

  • (?<plantNumber>\d{4}): Captures four consecutive digits (\d{4}) into a named capturing group plantNumber.
  • (?=P\d{2}|M-\d|W-\d): Positive lookahead assertion that ensures the captured plant number is followed by either “P” followed by two digits, “M-” followed by a digit, or “W-” followed by a digit. This ensures we only capture valid plant numbers in the context of the provided format.

Optimization:

This regex is optimized by using a lookahead assertion instead of capturing the trailing characters. This reduces the number of matches and improves performance.

Usage:

You can use this regular expression with various tools or libraries depending on your programming language or environment. For example, in C#, you can use it with Regex.Matches as shown in the previous example.

This optimized regex provides the same output as the previous solution but with potentially improved performance.

hi @vrdabberu @mukesh.singh @mkankatala

not solved yet,

when we manually copy the mail body, it’s working but when we this mail i get dynamically by, get outlook mail message activity , its not working for the same mail, it gives me blank output.

why this is not working for the dynamically receive mail body

please give me correct syntax for dynamic mail body.

Dyanamic mail body as per Below
@"From: Workflow System SAP_WFRT@GALAXYSURFACTANTS.COM
Sent: Friday,
February 23,
2024 12:23 PM
To: Yogesh Thakur yogesh.thakur@galaxysurfactants.com; Vijendra Joshi Vijendra.Joshi@galaxysurfactants.com; R.K.Singh Singh@galaxysurfactants.com; Sandeep Kapoor Sandeep.Kapoor@galaxysurfactants.com; Chetan Chandgaonkar Chetan.Chandgaonkar@galaxysurfactants.com
Subject: MDG MM Create Change Request completed

Dear User,
A master data request 7773 has been approved. A Material Master 1012014 ( Benzoic Acid Flakes ) has been created.

  1. Click here-> 7773 http://geccappl.gsl.com:8003/sap/bc/webdynpro/sap/mdg_bs_mat?CREQUEST=000000007773&CRTYPE=ZMATROH&ACTION=CREATE&IS_CREQ_MODE=X&WDCONFIGURATIONID=BS_MAT_INIT_07&SAP-CLIENT=400&SAP-LANGUAGE=EN (New material code - Benzoic acid Flakes) to log into MDG system.

Change Request Details:

Material Type:ROH(Raw materials)

Plant Details:

Plant

Plant Desc

1100

P01

2000

M-3

2200

W-67

Regards,
MDG Team

Note: This is a system generated email,
please do not reply.
Please contact SAP Team if you encounter any technical issues.
“Please note that the information and attachments in this email communication may contain confidential or privileged information and is for the exclusive use of the intended addressee only. Before opening and accessing the attachment,
if any,
please check and scan for virus. If you are not the intended recipient or if you have received this message erroneously,
please delete it from your computer permanently and immediately notify the sender. Any use,
forwarding,
printing,
storing,
disseminating,
distribution or copying of such unintended or erroneously received email communication and its attachments is prohibited.”

“Please note that the information and attachments in this email communication may contain confidential or privileged information and is for the exclusive use of the intended addressee only. Before opening and accessing the attachment,
if any,
please check and scan for virus. If you are not the intended recipient or if you have received this message erroneously,
please delete it from your computer permanently and immediately notify the sender. Any use,
forwarding,
printing,
storing,
disseminating,
distribution or copying of such unintended or erroneously received email communication and its attachments is prohibited.” "

@mkankatala @vrdabberu @mukesh.singh
Please help me for the same for dynamic mail body (Mail Body Output received from Get outlook mail message activity)

Please Help me get the output with the Dynamic mail body form get outlook mail message

I have made a small mistake in the regular expression, could you check the below one for all of your mail bodies… @Ajinya_jorwekar

(?<=Plant Details:[\s\S]+)(?<!\s\d+\s)\d{4}(?=\s+[A-Z]+)
- Assign -> Output = String.Join(",", System.Text.RegularExpressions.Regex.Matches(Mail_Body.toString, "(?<=Plant Details:[\s\S]+)(?<!\s\d+\s)\d{4}(?=\s+[A-Z]+)"))

Check the below image for your better understanding,

Hope it helps!!