I have follow this comment and I’ve change a few adjustments to
w+[-.w]*@(?!.+(com|co.kr|net|org))w[-.w]*.+w{2,4}$
for match any domain, but except ".com" , ".net" , "co.kr" , ".org"
and contents in email body it’s working fine.
image_1
image_2
But if there is ".com" , ".net" , ".org" and "co.kr"
before another domain.
Or there is any symbol ( = , + ) it cannot match in this below.
image_3
Where do I change to fix this?
2
Answers
Today I've adjust regex completed. Exclude all desired domain
(".com" , ".net" , ".org" and "co.kr")
and another contents in email body.The result is perfect.
You are not getting a match in the last examples because you want to assert that the
.com
.net
.co.kr
.org
is at the end of the string using$
in the lookahead.Your last example with the
=
sign in image_3 does not match as there is no @ sign in:As there are no spaces in the match that you want, you can change the
.+
toS*
to not cross matching spaces.To match
.com
with the leading dot, you can add that to the pattern before starting the group.Note that starting the match with
w+
could still get a partial match if there is a non word character preceding it, and usingw
might limit the range of addresses that you actually want to match.To prevent that, you can start the pattern with
(?<!S)
but that has limited support.See a regex demo.