Java String Quote quotePattern(String s)

Here you can find the source of quotePattern(String s)

Description

Quotes a pattern.

License

Apache License

Declaration

public static String quotePattern(String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//  w ww . j a  va2  s.  c o  m
     * Quotes a pattern.
     */
    public static String quotePattern(String s) {
        s = s.replaceAll("\\\\", "\\\\");
        s = s.replaceAll("\\.", "\\\\.");
        s = s.replaceAll("\\+", "\\\\+");
        s = s.replaceAll("\\{", "\\\\{");
        s = s.replaceAll("\\}", "\\\\}");
        s = s.replaceAll("\\|", "\\\\||");
        s = s.replaceAll("[$]", "\\\\\\$");
        s = s.replaceAll("\\?", "\\\\?");
        s = s.replaceAll("\\*", "\\\\*");
        s = s.replaceAll("\\(", "\\\\(");
        s = s.replaceAll("\\)", "\\\\)");
        s = s.replaceAll("\\[", "\\\\[");
        s = s.replaceAll("\\]", "\\\\]");
        return s;
    }
}

Related

  1. quotEncode(String txt)
  2. quoteOutputName(String name)
  3. quoteParameter(String param)
  4. quotePath(String path)
  5. quotePattern(String pattern)
  6. quotePlainText(final String textContent)
  7. quoteQuery(String query)
  8. quoteReference(final String reference)
  9. quoteRegexMeta(final String input)