So my problem is I am looking to match a certain combination of letters at the start of an email address followed by an @ and then a wildcard, for example:
admin@* OR noreply@* OR spam@* OR subscribe@
Can this be done?
So my problem is I am looking to match a certain combination of letters at the start of an email address followed by an @ and then a wildcard, for example:
admin@* OR noreply@* OR spam@* OR subscribe@
Can this be done?
Try this
^(?:admin|noreply|spam|subscribe)@\S*
See it here on Regexr
You need an anchor at the start to avoid matching address with other characters before. If the string contains only the email address use ^ at the beginning, this matches the start of the string. If the email address is surrounded by other text, the use \b this is a word boundary.
(?:admin|noreply|spam|subscribe) is a non capturing group, becuase of the ?: at the start, then there is a list of alternatives, divided by the | character.
\S* is any amount of non white characters, this will match addresses that are not valid, but should not hurt too much.
Your looking for grouping with the | operator. The following will do what you want.
edit: Since your using this for an email server rules you won't need to match the entire string, only part of it. In that case you will need to use ^ to specify the start of the string and then drop the domain portion since we don't care about what it is.
^(admin|noreply|spam|subscribe)@
[\w.] is too restrictive, something like \S (a non whitespace character) would be probably better.sure thing!
[A-Za-z]+@.+
says any letters at least once but any number of times, then an at sign, then anything (other than newline) for your specific examples use
(admin|noreply|spam|subscribe)@.+