Regex Match Error while extracting email address

@Lum Now I would have to know if this operation is after that operation which was done in the other post and the input to this operation is the output of that operation
or
If data is different from that and if there is no connection to the other post, I would like to get a sample of this data and then maybe I can provide the right solution.

I hope you can understand what I meant :sweat_smile:

This operation is part of the html email issue (in another post), to retrieve email address value.
What I just realised is that the company implemented auto insertion of the two lines in red bold text β€œEmail is from external source. Do not click on links or open files if unsure of sender.” So we ended up with fetching from the first Email input " is from external source." using the earlier solution you provided, instead of the email address β€œjabezjireh@hotmail.com”.
Hence I need your help to modify the solution so that it fetches the email address instead.

So this was the Expression used earlier. I’ll try to modify it and provide you a unique way to identify the email based on the Data in the Image that you have provided.

@Lum Try using this expression :

System.Text.RegularExpressions.Regex.Match(mail.Body,β€œ(?<=Email).*:.*”).Value.ToString.Replace(β€œ:”,β€œβ€).Replace(β€œ[”,β€œβ€).Replace(β€œ]”,β€œβ€).Trim

Thank you. This works wonderfully.
On another regex result below, I have 2 match results. How do I fetch the 2nd match to get β€œjabezjireh@hotmail.com”?

@Lum Will the Second β€œFrom :” have > at the end always ? Or if that β€œFrom :” is always it’s last occurrence and if there won’t be any occurrences of β€œFrom :” in the body of mail, then we can alter the Expression to take from the last.

@Lum An Additional Regex option at the end should get what you needed. Check the expression below :

System.Text.RegularExpressions.Regex.Match(mail.Body,"(?<=From).*:.*",RegexOptions.RightToLeft).Value.ToString.Replace(":","").Replace("[","").Replace("]","").Trim

The option RightToLeft should get you the first Match from the last.

Yes the new expression is giving me the correct β€œFrom:” results as shown below.
Capture1
But I need the name β€œAKSHAY SAPRE” using one expression and β€œjabezjireh@hotmail.com” in another expression. Is it possible?

@Lum After you get the β€œFrom:” value in a String you can use Split based on β€œ<” So that the first Split will contain the name and the next split will contain Email. You might need to use the below Split method.

Split(fromValue,β€œ<”)(0) - Get Name
Split(fromValue,β€œ<”)(1).ToString.Replace(β€œ>”,β€œβ€).Trim - Get Email

The Split method works and the correct value is displayed in the message boxes.

Capture1
Capture2
However, when I run, there is an error message shown below.
I have isolated the issue to the email address value, as the error pops out when subject and body are blanked out. Can you help please?
Capture3

@Lum What is the email Address value, is it blank for that particular time that you get the error?
It might contain extra spaces, use Email_Address.Trim and check

It is still the same error when I added Email_Address.Trim
The email address is displayed in message box but somehow when it comes to Send outlook mail step, it cannot recognise the Email_Address variable.


Capture1

@Lum Ok. Can you debug and check ? Also Try Hard coding that value and check if mail can be sent to that particular mail.

Oh I see what my issue is now. The email address regex is fetching name and name regex is fetching email address instead. After swopping, it works perfectly. Thanks for your guidance.

2 Likes