簡體   English   中英

java - 如何從java中的字符串中刪除大括號{}內的內容以及大括號?

[英]How to remove content inside curly braces{} along with the braces from a string in java?

例如我有一個字符串:-

High PM2.5 found in {$coordinate} and address is {$geoAddress} and solution found in {$solutionCoordinate} and address is {$solutionAddress}.

我想從此字符串中刪除花括號中的所有內容,輸出應為:-

High PM2.5 found in and address is and solution found in and address is.

我在java中嘗試了幾個正則表達式來解決這個問題。 我得到了正確的{$geoAddress} , String message = High PM2.5 在 {$coordinate} 中找到,地址是{$geoAddress} ,解決方案在{$solutionCoordinate} ,地址是{$solutionAddress}

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM