簡體   English   中英

帶組的Java正則表達式

[英]Java regular expression with groups

我想替換所有出現的字符串,例如:

"{something1}
"{someother2}
"{thing3}

但是如何處理包含字符串而不是字符的組?

-編輯:

例如給定的字符串:

sometext "{something1}hello

我想擁有

sometext hello

或更好,但是它只有replaceAll參數

sometext "hello

我猜你可以使用replaceAll

String b = a.replaceAll("\\{.*?\\}", "sometext ");

這會將所有用大括號括起來的字符替換為替換字符串。

只需使用|構建正則表達式| 組內的運算符。

您可以使用或'|' 匹配完整字符串的運算符-

subject.replace(/something1|someother2|thing3/g, ","); 

暫無
暫無

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

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