簡體   English   中英

我如何Java正則表達式查找和替換

[英]How do I java regex find and replace

什么是用於刪除括號及其之間所有內容的正則表達式?

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

我試過了:

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

您正在使用正斜杠字符轉義()特殊字符。 您需要使用反斜杠:

String output = input.replaceAll("\\(.*?\\)", "");

暫無
暫無

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

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