2013-04-04 56 views
0

我想倒置一个正则表达式,我想匹配所有没有特殊电子邮件用户名的字符串。如:在正则表达式中,这是什么--->“?!”

my email is [email protected] and I love programming 
my email is [email protected] and I love programming 
my email is [email protected] and I love programming 
my email is [email protected] and I love programming 

全部不应该匹配。

如果我想匹配他们,我使用/[email protected]*[\.].*/。一位朋友告诉我,如果我想反转它,我必须使用?!,但我不知道如何?

+0

请看这里:: http://stackoverflow.com/questions/10804732/what-is-the-difference-between-and-in-regex – 2013-04-04 06:03:19

+0

你不需要反转正则表达式,你只需要反转匹配功能。例如。 'if(!str.match(/.../))'...... – deceze 2013-04-04 06:05:33

+0

这不好。我想使用正则表达式本身 – Myriam 2013-04-04 06:09:33

回答

1

(?!)排除模式

所以,你的正则表达式将是

^(?!.*[email protected]\.com).*$ 

Regex不需要这个问题,你可以改用indexOf的方法来检查,如果字符串包含该特定的电子邮件

+0

我不知道你为什么会建议正则表达式的解决方案。虽然这是正确的,但在这种情况下是不必要的。 – nhahtdh 2013-04-04 07:07:40

+0

@nhahtdh yes..you are right!编辑答案..谢谢 – Anirudha 2013-04-04 07:17:15