Regex to extract only top data from email body

Hi Everyone,
I want to extract the top name from the email body from the below email template.

From : Alex
To : Tom
Content: Contract
I need to renew contract

From : Jim
To : Shiva
Contect: Contract Renewal Cancellation
I don’t need to renew the contract

The above is the example of email body, I want to extract the top name only from every email. Kindly suggest the regex expression to extract the top name only.

Thanks in advance

@Binod_Kumar_Biswal,

What should be the output?

From : Alex
To : Tom
Content: Contract
I need to renew contract

This one?

Hi @ashokkarale,

Output should be “Alex”

Thanks

Hi @Binod_Kumar_Biswal

Try this

(?<=From\s*:\s*)(\w+)

System.Text.RegularExpressions.Regex.Match(Input,"(?<=From\s*:\s*)(\w+)").Value.Trim

Regards,

Hi @lrtetala ,

Thanks for your response.

But I want to extract only the first name i.e., Alex out of while content but with this this it will extract Alex and Jim right ?

I want the top name only from the entire email body.

@Binod_Kumar_Biswal

It extracts the top name only i.e., first match

System.Text.RegularExpressions.Regex.Match(Input,"(?<=From\s*:\s*)(\w+)").Value

Another way, try below

System.Text.RegularExpressions.Regex.Matches(Input,"(?<=From\s*:\s*)(\w+)")(0).Value

Regards,

Hi @Binod_Kumar_Biswal

Instead of using regex you can use substring method as well,
below is the syntax to extract the first value after 'From : ’ and attaching screenshot as well for your reference

strInput.Substring(strInput.IndexOf("From : ")+"From : ".Length).Trim.Split(Environment.NewLine.ToCharArray)(0).

if you want in regex format you can use below syntax in assign activity,
System.Text.RegularExpressions.Regex.Match(strInput,“(?<=From\s*:\s*)(.*)[^\r\n]”).ToString

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