[英]How to remove content inside curly braces{} along with the braces from a string in java?
For example I have a string:-例如我有一个字符串:-
High PM2.5 found in {$coordinate} and address is {$geoAddress} and solution found in {$solutionCoordinate} and address is {$solutionAddress}.
I want to remove everything in curly braces from this string and the output should be:-我想从此字符串中删除花括号中的所有内容,输出应为:-
High PM2.5 found in and address is and solution found in and address is.
I was trying several regex in java to solve this.我在java中尝试了几个正则表达式来解决这个问题。 I have got the right one, String message = High PM2.5 found in {$coordinate} and address is {$geoAddress}
and solution found in {$solutionCoordinate}
and address is {$solutionAddress}
.我得到了正确的{$geoAddress}
, String message = High PM2.5 在 {$coordinate} 中找到,地址是{$geoAddress}
,解决方案在{$solutionCoordinate}
,地址是{$solutionAddress}
。
message = message.replaceAll("\\{[^}]*\\}", "");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.