Here you can find the source of quotePattern(String s)
public static String quotePattern(String s)
//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; } }