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