Regular expression to match email except for specific email address(es)
I need a regular expression that will match email addresses, but exclude specific email addresses from the match
eg Do not match (exclude these addresses from match);
sponge.bob@example.com
jim.bob@example.com
billy.bob@example.com
match all other email addresses (include any other valid email address);
test@example.com
no.body@example.com
another.test.email@example.com
and.another.one@example.com.au
I tried using a negative lookbehind expression but couldn't figure out how to get it working (if even possible via that method). It would be beneficial to be able to specify multiple excluded emails, but at least one exclusion would be minimum required.
Thanks
(?:^|(?<=s))(?!sponge.bob@example.com|jim.bob@example.com|billy.bob@example.com)(w[w.]*@w+.[w.]+)b
See demo here.
explanation
(?:^|(?<=s)) //appears at start of line or after space
(?! //Don't match if it starts with the below
sponge.bob@example.com|
jim.bob@example.com|
billy.bob@example.com
) //End exclusions
( //Capture group for emails, you don't need this
w //Start with [A-Za-z0-9_]
[w.]* //Zero or more of [w.]
@
w+ //Start with one or more [A-Za-z0-9_]
. //Forces to have atleast one dot
[w.]+ //followed by one or more of [w.]
) //End capture group for emails, remove it with the matching group
b //Should end with word boundary.
链接地址: http://www.djcxy.com/p/92648.html