Extracting required URL from mail body using Regex

Hi All,

I have taken get exchange mail activity, removing unwanted text from body, want to extract a URL from mail body. Can anyone help me to extract only URL from mail body using regex.

I will be reading mail one by one.

I want to assign these regex to some string variable.

can someone please help…

Please find the sample mail:

The following store has been approved Location No : 21872 India : Mumbai AIf @ MAST Market No : 464738 https://pdportal.8-ten.com/Main/ProjectMain.aspx?projectLocationId=427409

Hi,

try this:

output = System.Text.RegularExpressions.Regex.Match(your_String,"(?=http).+").Value

Preview link: regex101: build, test, and debug regex

1 Like

Hi @Adrian_Star ,

It works… Thank You for the help…

And my one more doubt is…if there is an extra text after end of URL.

If I want to stop at end of URL “427409”. How can I change the regex…

Please Help.

Something like this:

output = System.Text.RegularExpressions.Regex.Match(your_String,"(?=http)\S+").Value

Preview link: regex101: build, test, and debug regex

1 Like

Hi @Adrian_Star ,

Thanks for the help…

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