[英]Java regex - replace substrings between delimiters with same substrings without delimiters
我试图弄清楚如何用Java 1.6替换字符串
hello ${world }! ${txt + '_t'}<br/> ${do_not_replace
在没有这些分隔符的情况下,使用相同子字符串在“ $ {”和“}”之间标识的任何子字符串。 所以上面字符串的输出应该是
hello world ! txt + '_t'<br/> ${do_not_replace
我确定了一种工作模式,该模式允许我用固定字符串替换子字符串
str.replaceAll('[${](.*?)}', '_')
而且我知道我不能在此版本的Java中使用命名组。
任何有关此问题的简单解决方案的建议都将受到赞赏! 非常感谢
尝试
s = s.replaceAll("\\$\\{(.+?)}", "$1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.