title: How to make the regex from .replaceAll(String regex, String replacement) safe for Userinput?
body: <p>In a programm like this:</p>
  
  <pre><code>String userInput = "[]";
  String str = "Hello World[]!";
  String replacement = "";
  str = str.replaceAll(userInput, replacement);
  System.out.print(str);
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 1
  []
  </code></pre>
  
  <p>But I want the ouput:</p>
  
  <pre><code>Hello World!
  </code></pre>
  
  <p>Is there are way to make userInput safe for replaceAll? Let's say the userInput is: <code>[]</code>. How do I need to process the String to always replace the String an not the meaning of the String. </p>