gpt4 book ai didi

要匹配的 Java 模式;在 & 中跳过它

转载 作者:行者123 更新时间:2023-12-01 09:37:58 25 4
gpt4 key购买 nike

Java 正则表达式中是否有模式可以匹配;同时跳过&喜欢文字吗?

最佳答案

您需要正则表达式,例如:(?<!&amp); Demo and Exaplaination

正则表达式的含义:查找前面没有&;

代码示例:

Pattern pattern = Pattern.compile("(?<!&amp);");
Matcher matcher = pattern.matcher("; abd &amp; this is what ;");
while(matcher.find()){
System.out.println("find start position "+matcher.start() +" find end position "+matcher.end()+" find for "+ matcher.group(0));
}

O/P

find start position 0 find end position 1 find for ;

find start position 25 find end position 26 find for ;

关于要匹配的 Java 模式;在 & 中跳过它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38690344/

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