Nagative Lookahead

前端之家收集整理的这篇文章主要介绍了Nagative Lookahead前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
http://stackoverflow.com/questions/1749437/regular-expression-negative-lookahead A negative lookahead says,at this position,the following regex can not match. Let's take a simplified example: a(?!b(?!c)) a Match: (?!b) succeeds ac Match: (?!b) succeeds ab No match: (?!b(?!c)) fails abe No match: (?!b(?!c)) fails abc Match: (?!b(?!c)) succeeds The last example is a double negation: it allows a b followed by c. The nested negative lookahead becomes a positive lookahead: the c should be present. In each example,only the a is matched. The lookahead is only a condition,and does not add to the matched text. 如果写了这样的正则表达式 a(?!b) 就表示匹配所有后面没有b紧跟着的a. 也就是说"ab aa ac ad" 就会匹配到 (a)a a(a) (a)c (a)d 这里只有ab的a是匹配不到的, 因为后面紧跟着b 原文链接:https://www.f2er.com/regex/361678.html

猜你在找的正则表达式相关文章