I want to write a regex (java script) to match if the given text not contain only an email string.
for ex:
- abc -> should match
- [email protected] sss -> should match
- [email protected] -> should match
- aaa [email protected] -> should match
- [email protected] -> should not match
I wrote a regex using (?<!…) Negative lookbehind, to check whether given text does contain only email string or not as below. But I cant use + inside lookbehind expression and it gives A quantifier inside a lookbehind makes it non-fixed width error.
regex:
^.+(?<!([a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.com))$
explanation:
([a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.com)- regex to check email address.^.+(?<!([a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.com))$- regex to check look behind of all non empty texts(.+)
Please give me an idea to resolve this issue...
Thanks
One approach is to enclose the pattern of an email address in a negative lookahead assertion with anchors:
Demo: https://regex101.com/r/gutJB8/1
Note that your example of
[email protected]in the question should not match even though you claim that it should.