Regex Need for following scenario

I received string in body of email and i extract that as a string from that sring i need to etract To mail id and CC mail id using Regex.

**To: aa bb aa.bb@XYZ.com; E K e.k@XYZ.com; P Z pz@XYZ.com; P P pp@XYZ.com; A A aa@XYZ.com; **
Cc: M B mb@XYZ.com

Here i need two regex

1 To Mail address o/p like,
aa.bb@XYZ.com
e.k@XYZ.com
pp@XYZ.com
aa@XYZ.com

Then another regex
cc mail id
mb@XYZ.com

Thanks,
Vicky K

@Vicky_K

are stars and all are part of the string you get?

if yes then first split using Cc: arr_String = str.Split({"Cc:"},StringSplitOptions.None)

str is the string variable where the strng is stored

arr_string is the array output

now to get all to fields use this…which will add add the values extracted with Newline character and give as one string

tovalues = String.Join(Environment.NewLine,System.Text.RegularExpressions.Regex.Matches(arr_String(0),"[^ ]+(?=@)[^ ;]+"))

ccvalues = String.Join(Environment.NewLine,System.Text.RegularExpressions.Regex.Matches(arr_String(1),"[^ ]+(?=@)[^ ;]+"))

Hope this helps

cheers

Hi,

Can you try the following sample?

Sample
Sample20231031-4L.zip (2.7 KB)

Regards,

Hi @Vicky_K ,
Thanks for reaching out to UiPath Community.

Here are the regexpattern that you can use.
Extract To Email Address: To: (.?@.?:wink:
Extract CC email Address: Cc: (.@.)

Regards,
@pratik.maskar

i received o/p using above one but still i have aa.bb@YZ.com
but i don’t want <> this one i need only mail id like this aa.bb@YZ.com

@Vicky_K

Can you please show a screenshot of what you are getting

may be you typed something but not able to see …try usign performatted text (</>)

cheers

Hi @Vicky_K

Split the text:

parts = inputText.Split({"Cc:"}, StringSplitOptions.RemoveEmptyEntries)
toPart = parts(0).Trim()
ccPart = parts(1).Trim()

Regex for toPart and ccPart:

System.Text.RegularExpressions.Regex.Matches(toPart, "(?<=[:|;]\s\w+\s\w+\s)\w+\.?\w+\@\w+.\w+")
System.Text.RegularExpressions.Regex.Matches(ccPart, "(?<=[:|;]\s\w+\s\w+\s)\w+\.?\w+\@\w+.\w+")

Or you can use this also "\w+?[.]?\w+@\w+.\w+" instead of above

@Vicky_K

Input: **To: aa bb aa.bb@XYZ.com; E K e.k@XYZ.com; P Z pz@XYZ.com; P P pp@XYZ.com; A A aa@XYZ.com; **

You can try this regex expression it will work for both the To and CC values

RegexExpression : - [A-Za-z@.]+(?:com)

OutPut:

image