I need a regex to match phishing email names, where a specific name or word is NOT found.
For example…
John Smith (notmyemail@sodifh.com)
John Smith (notmyemail@SODI.com)
John Smith (jsmit34@gmail.com)
John Smith (myRealEmail@mymail.com)
Where the bottom email is the only legit email, and needs to be ignored.
I have tried similar to:
^(J|j)ohn.(S|s)mith.*\@^((?i)\bmymail\.com\b)*$
But this fails to select the 3 bad emails.
Also tried similar to:
^(J|j)ohn.(S|s)mith.*@gmail\.com
but this method only removes the Gmail one.
How can I properly pattern match to remove all bad emails regardless of letter case, and to only allow one domain (in this case mymail.com) and no others?
>Solution :
You may use this regex with a negative look ahead condition
^[jJ]ohn.[sS]mith[^@]*@(?!mymail\.com).+
RegEx Details:
^: Start[jJ]ohn: MatchJohnorjohn.: Match any character[sS]mith[: MatchSmithorsmith[^@]*: Match 0 or kore of any character except@@: Match a@(?!mymail\.com): Negative lookahead to fail the match if we havemymail.comis at next position.+: Match 1+ of any character