Here you can find the source of replaceWildcards(String wildcardPattern)
public static String replaceWildcards(String wildcardPattern)
//package com.java2s; /*//from w ww. jav a 2 s .c o m * Data Scrambler, Data Generation API * Copyright (c) 2015, Sergiu Prutean. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. */ import java.util.*; public class Main { private static final Set<Character> PREFIXED_CHAR_SET = new HashSet<Character>( Arrays.asList('+', '(', ')', '^', '$', '.', '{', '}', '[', ']', '|', '\\')); public static String replaceWildcards(String wildcardPattern) { final StringBuilder builder = new StringBuilder(); builder.append('^'); boolean replaced = false; final int length = wildcardPattern.length(); for (int i = 0; i < length; ++i) { final char ch = wildcardPattern.charAt(i); if (ch == '*') { builder.append(".*"); replaced = true; } else if (ch == '?') { builder.append("."); replaced = true; } else if (PREFIXED_CHAR_SET.contains(ch)) { builder.append('\\').append(ch); } else { builder.append(ch); } } builder.append('$'); return replaced ? builder.toString() : wildcardPattern; } }