I want to discard a string if some words are present before the character @ in it.
Example:
I want words foo and bar that should NOT be present on a string before @ symbol but the same words are allowed after @ symbol.
I do NOT want these:
abcfooxyz@domain.com
barabc@domain.com
barabc@domainfoo.com
I want these:
abcxyz@domainfoo.com
pqrabc@domainbar.com
pqrabc@domain.com
I have regex ^((?!(foo|bar)).)*$, but it also discards strings that have foo and bar after @ symbol even if the words are NOt present before @.
I only want it to discard if foo or bar is present before @ symbol in a string.
Do you have an idea how can I do it?
Thanks.
>Solution :
You need to assert at each character position preceding the @ that it is not the start of foo or bar:
^((?!foo|bar).)+@.*$