简体   繁体   English

如何在Java中使用$ +或$&正则表达式?

[英]How can I use the $+ or $& regular expressions in Java?

I've been searching for a while trying to figure out why this wont work- I found the exact thing I want to accomplish Simple regex replace to keep original string but I can't seem to use the regular expression $+ or $& in Java like so: 我一直在寻找一段时间,试图弄清楚为什么它不起作用-我找到了我想要完成的简单操作:正则表达式替换以保留原始字符串,但我似乎无法使用正则表达式$+$& Java是这样的:

String S1 = "bob";
String S2 = "the builder";
Pattern p = Pattern.compile(S1, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(ST);
ST = m.replaceAll("$+/"+S2);

使用$0来表示替换模式中的整个匹配项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM