I'm trying to do the following using regular expression (java replaceAll):
**Input:**
Test[Test1][Test2]Test3
**Output**
TestTest3
In short, i need to remove everything inside square brackets including square brackets.
I'm trying this, but it doesn't work:
\\[(.*?)\\]
Would you be able to help?
Thanks,
Sash
解决方案
You can try this regex:
\[[^\[]*\]
and replace by empty
Sample Java Source:
final String regex = "\\[[^\\[]*\\]";
final String string = "Test[Test1][Test2]Test3\n";
final String subst = "";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
final String result = matcher.replaceAll(subst);
System.out.println(result);