Here you can find the source of escapeRegexp(final String str)
public static String escapeRegexp(final String str)
//package com.java2s; import java.util.Arrays; public class Main { private static final char[] REGEXP_CHARS = new char[] { '\\', '[', ']', '(', ')', '{', '}', '^', '$', '|', '?', '*', '+', '-', ':', ',', '.', '&' }; public static String escapeRegexp(final String str) { if (str == null) { return null; }//w w w.jav a 2 s .c o m final StringBuffer buf = new StringBuffer(); final int len = str.length(); for (int i = 0; i < len; i++) { final char c = str.charAt(i); if (Arrays.binarySearch(REGEXP_CHARS, c) >= 0) { buf.append("\\"); } buf.append(c); } return buf.toString(); } }