0

What's the regex for removing parentheses and everything between?

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

I tried:

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

1 Answer 1

1

You are using forward slash characters to escape the ( and ) special characters. You need to use backslashes:

String output = input.replaceAll("\\(.*?\\)", "");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.