2014-08-28 24 views
0

什麼是正則表達式刪除括號和之間的一切?我如何正則表達式查找和替換

input = "hello world (this is a test1) (test 2) hello"; 
output = "hello world hello"; 

我想:

str.replaceAll("//(.*?//)", ""); 

回答

1

您使用正斜槓字符逃脫()特殊字符。您需要使用反斜槓:

String output = input.replaceAll("\\(.*?\\)", ""); 
相關問題