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:
Do you have a more specific suggestion for getting the characters between the “@” symbol and the “.com”?
@UiUser Try below regex.
var = Fname.Lname@company.com
System.Text.RegularExpressions.Regex.Match(str,"(?<=@).+(?=.com)").ToString
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.
cheers
Happy learning
([^@]+).\w+$
@ANSHUL if i use that regex it contains part of the .com would it be possible to alter it to only get before the period?
Hi @UiUser
Between @ and first .
(?<=@).+?\b
Between @ and last .
(?<=@)(.+)(?:\..+?)$
Between @ and last .
Exclude the two last groups if .co.something
(?<=@)(.+?)(?:\.co\b)?(?:\.[^.]+?)$