简体   繁体   中英

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. 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} .

message = message.replaceAll("\\{[^}]*\\}", "");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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