title: How do I escape '+' in pattern matching to highlight keyword?
body: <p>I'm implementing a keyword highlighter in Java.  I'm using <code>java.util.regex.Pattern</code> to highlight (making bold) keyword within String content.  The following piece of code is working fine for alphanumeric keywords, but it is not working for some special characters.  For example, in String content, I would like to highlight the keyword <code>c++</code> which has the special character + (plus), but it's not getting highlighted properly.  How do I escape <code>+</code> character so that <code>c++</code> is highlighted?</p>
  
  <pre><code>public static void main(String[] args)
  {
      String content = "java,c++,ejb,struts,j2ee,hibernate";
      System.out.println("CONTENT: " + content);
      String highlight = "C++";
  
      System.out.println("HIGHLIGHT KEYWORD: " + highlight);
  
      //highlight = highlight.replaceAll(Pattern.quote("+"), "\\\\+");
      java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("\\b" + highlight + "\\b", java.util.regex.Pattern.CASE_INSENSITIVE);
      System.out.println("PATTERN: " + pattern.pattern());
      java.util.regex.Matcher matcher = pattern.matcher(content);
  
      while (matcher.find()) {
          System.out.println("Match found!!!");
          for (int i = 0; i &lt;= matcher.groupCount(); i++) {
          System.out.println(matcher.group(i));
          content = matcher.replaceAll("&lt;B&gt;" + matcher.group(i) + "&lt;/B&gt;");
          }
      }
      System.out.println("RESULT: " + content);
  }
  </code></pre>
  
  <p><strong>Output:</strong><br>
  CONTENT: java,c++,ejb,struts,j2ee,hibernate<br>
  HIGHLIGHT KEYWORD: C++<br>
  PATTERN: \bC++\b<br>
  Match found!!!<br>
  c<br>
  RESULT: java,<B>c</B>++,ejb,struts,j2ee,hibernate</p>
  
  <p><hr>
  I even tried to escape '+' before calling <em>Pattern.compile</em> like this,</p>
  
  <pre><code>highlight = highlight.replaceAll(Pattern.quote("+"), "\\\\+");
  </code></pre>
  
  <p>but still I'm not able to get the syntax right.  Can somebody help me solve this?</p>