Regex email address

I am trying to get just the company part of the email address of a sender using regex. What regex code should i use to extract “company” from this example string:

Fname.Lname@company.com

Hi @UiUser

Hope this link might be helpful to you RegEx

cheers :smiley:

Happy learning :smiley:

Do you have a more specific suggestion for getting the characters between the “@” symbol and the “.com”?

Hi @UiUser

Do you wan’t only the company in the string right ?

cheers :smiley:

Happy learning :smiley:

@UiUser Try below regex.

var = Fname.Lname@company.com

 System.Text.RegularExpressions.Regex.Match(str,"(?<=@).+(?=.com)").ToString
1 Like

Easier to do without regex if this would work for you.

email.Split("@“c)(1).Split(”."c)(0)

where email = “Fname.Lname@company.com

Hi @UiUser

Here i created a sample of getting the value company hope it make sense.

Scenario 1: Assign the value to string Variable
2:Split the array that consist of “@” and “.com”
3:Then get the value of the splitted array

See image below for your reference.

image

cheers :slight_smile:

Happy learning :smiley:

([^@]+).\w+$

@ANSHUL image if i use that regex it contains part of the .com would it be possible to alter it to only get before the period?

Try this
(?<=@)(.*?)(?=.)

Hi @UiUser

Between @ and first .
(?<=@).+?\b

Between @ and last .
(?<=@)(.+)(?:\..+?)$

Between @ and last .
Exclude the two last groups if .co.something
(?<=@)(.+?)(?:\.co\b)?(?:\.[^.]+?)$

image

image

image