Here you can find the source of toJavaPattern(String pattern)
private static String toJavaPattern(String pattern)
//package com.java2s; //License from project: Open Source License public class Main { private static String toJavaPattern(String pattern) { StringBuilder result = new StringBuilder("^"); char metachar[] = { '$', '^', '[', ']', '(', ')', '{', '|', /* '*', */'+', '?', '.', '/' }; for (int i = 0; i < pattern.length(); i++) { char ch = pattern.charAt(i); boolean isMeta = false; for (char aMetachar : metachar) { if (ch == aMetachar) { result.append("\\").append(String.valueOf(ch)); isMeta = true;// ww w . j a v a2 s . com break; } } if (!isMeta) { if (ch == '*') { result.append(".*"); } else { result.append(ch); } } } result.append("$"); return result.toString(); } }