我的 java @windows 是:
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode, sharing)
代码
Pattern.compile(".+(?<!(xxx|idea|perforator|pycharm|s).*)").matcher("xxx").matches() //returns TRUE while it should return FALSE
Pattern.compile(".+(?<!(xxx|idea|perforator|pycharm|s).*)").matcher("perforator").matches() //returns FALSE
如果字符串小于 8 个字符,则负后视看起来会失败。
这是错误还是我对正则表达式有什么误解?
最佳答案
Java 中的 Lookbehinds 不能有像 .*
这样的可变长度的东西,只有像交替和有限重复这样的东西。
更多信息:http://www.regular-expressions.info/lookaround.html#limitbehind
关于java负向后看正则表达式错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9727235/