0

i want to invert a regular expression, i want to match all strings which doesnt have a special email username in them. like:

my email is myriam@example.com and I love programming
my email is myriam@yahoo.com and I love programming
my email is myriam@google.com and I love programming
my email is myriam@gmail.com and I love programming

all shouldn't be matched.

if i want to match them i use /myriam@.*[\.].*/. a friend told me that if i want to invert it, i must use ?!, but i can't find out how?

Myriam
  • 3
  • 1

2 Answers2

1

(?!) is negative lookahead

So your regex would be

^(?!.*myriam@example\.com).*$

Regex is not required for this problem you can instead use indexOf method to check if the string contains that particular email!

Anirudha
  • 32,393
  • 7
  • 68
  • 89
  • I don't know why you would suggest regex solution. Although it is correct, it is unnecessary in this case. – nhahtdh Apr 04 '13 at 07:07
0

It's negative lookahead. See here

Barmar
  • 741,623
  • 53
  • 500
  • 612