Replace everything between [ and ] in regex java
java, regex
Solution
Use `String#replaceAll`:
String s = "ab[cd]e";
s = s.replaceAll("\\[.*?\\]", ""); // abe
This will replace `[`, `]`, and everything in between with an empty string.
Problem
I need to remove everything between `[ ]`. Example: My Input : `ab[cd]e` Expected Output : `abe`. I tried using `\[` and `\]`, but it is reported as an illegal escape sequence. Can anyone please help me with this. P.S.: I am using Java 1.7.