I am a bit new to Regular Expressions. I am trying to create a Regular Expression in Java with a variable inside.
I would like to match "var", "(var)", "[var]", or "{var}" and any case variation of the variable var.
I have tried this, and it seems to have an exception:
java.util.regex.PatternSyntaxException: Unclosed character class near index 20
Does anyone have any suggestions how to fix and improve this?
String s = "[Tom] The rest of the title";
String v = "Tom";
s = s.replaceAll("(?i)[({/[]*" + v + "[)}\]]*", "");
System.out.println(s);
[Tom)match in your example?