我用Pattern作爲replaceAll方法中的參數,我想刪除打開和關閉括號(包括括號字符)內的所有字符,但只有在字符內刪除,括號仍然存在。下面是我的Java代碼如何使用字符串中的模式replaceAll
String test = "This is my test (inside the brackets) and finish here";
String regex = "\\(.*\\)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(test);
String out = test.replaceAll(matcher.group(), "");
System.out.println(out);
輸出This is my test() and finish here.
我很確定他也想擺脫括號。查看我的回答,瞭解我的想法。 –
我想在同一行,然後在問題中看到這個:'輸出是這是我的測試()並在這裏完成。「# – anubhava