gpt4 book ai didi

Java 正则表达式在包含引号的字符串上中断

转载 作者:行者123 更新时间:2023-11-29 05:52:33 25 4
gpt4 key购买 nike

"\"a".matches("a") 返回 false。这是怎么回事?

最佳答案

matches method expects the entire string to match ,而不仅仅是存在于目标字符串内某处的匹配项。

另一方面,returns true,因为它允许字符串包含匹配之前或之后的任何内容:

"\"a".matches(".*a.*")

另一种在字符串中的任何位置查找匹配项的方法是使用 Pattern直接:

if (Pattern.compile("a").matcher("\"a").find()) {
...
}

关于Java 正则表达式在包含引号的字符串上中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13390122/

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