Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有可能.replaceAll():
.replaceAll()
输入>
asd fs#{FIRST}l sdfj s#{SECOND}ijfio s#{THIRD}df o#{1}sj
输出>
asd fsFIRSTl sdfj sSECONDijfio sTHIRDdf o#{1}sj
这#\{[A-Za-z]+\}会找到整个#{aaa}但我不想删除里面的文本..
#\{[A-Za-z]+\}
当然,您可以使用capture groups:-
capture groups
String str = "asd fs#{FIRST}l sdfj s#{SECOND}ijfio s#{THIRD}df o#{1}sj"; str = str.replaceAll("#\\{([A-Za-z]+)\\}", "$1");
如果您想对此进行任何解释,请询问。我认为,代码是不言自明的。