Java 中对字符串进行以下替换的最佳方法是什么:
我的文本看起来与此类似:
one two [[**my_word** other words]] three four [[**my_other_word** other words]] five six
我想要以下文本
one two **my_word** three four **my_other_word** five six
我尝试使用正则表达式捕获组,但如何将一个捕获组替换为另一个捕获组?
最佳答案
使用
https://www.tutorialspoint.com/java/java_string_replaceall.htm
并做类似的事情
a.replaceAll("\\[\\[(\\w+)[^\\[]+\\]\\]", "$1");
关于java - 将 Java 正则表达式捕获组替换为其自身的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41961362/