0
什麼是正則表達式刪除括號和之間的一切?我如何正則表達式查找和替換
input = "hello world (this is a test1) (test 2) hello";
output = "hello world hello";
我想:
str.replaceAll("//(.*?//)", "");
什麼是正則表達式刪除括號和之間的一切?我如何正則表達式查找和替換
input = "hello world (this is a test1) (test 2) hello";
output = "hello world hello";
我想:
str.replaceAll("//(.*?//)", "");
您使用正斜槓字符逃脫(
和)
特殊字符。您需要使用反斜槓:
String output = input.replaceAll("\\(.*?\\)", "");