Extract email from a string

I wanted to extract email from the given string, for e.g. “My email id is (test.113@gmail.com)”, I tried using the IndexOf method to get index of @, and then extracting in 2 parts, like emailAddresspart1 (string before @), and emailAddresspart2 (string after @), but in output I’m getting this - “(test.113@gmail.com”. I don’t want that bracket before email
Please help me with this.

Thanks

Hi @vaibhavrpa1

You can try with Regex

You can use this Expression in string variable

System.Text.RegularExpression.Regex.Match(YourinputVariable,"(?<=()\S+(?=))").ToString

image

Regards
Sudharsan

1 Like

Hi @vaibhavrpa1

Welcome to Community

Check with the pattern below to extract email using regex!

([a-zA-Z0-9_-.]+)@([a-zA-Z0-9_-.]+)\b

System.Text.RegularExpression.Regex.Matches(YOurStringVar,"
([a-zA-Z0-9_-.]+)@([a-zA-Z0-9_-.]+)\b").Value

Reference Link below!

Regards

1 Like

Thank you for helping, but is there any other way to do so. I don’t want to use regex.

Hi @vaibhavrpa1

How about Using Split and replace!

InputStr = "My email id is (test.113@gmail.com)"

Split(testStr,"(")(1).Replace(")","")

image

Regards

1 Like

Thank you @pravin_calvin this works for me.

1 Like

Hi @vaibhavrpa1

Mark Solution to the post and close the thread so that it may helpful to others who searches similar!

Happy Automation!

Regards

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