gpt4 book ai didi

java负向后看正则表达式错误?

转载 作者:行者123 更新时间:2023-11-29 03:48:35 25 4
gpt4 key购买 nike

我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com