Here you can find the source of wildcardMatch(String string, String pattern)
public static boolean wildcardMatch(String string, String pattern)
//package com.java2s; /**//from w ww. j av a 2 s. c o m * * dry-redis: In-memory pure java implementation to Redis * Copyright (c) 2016, Sandeep Gupta * * http://sangupta.com/projects/dry-redis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ public class Main { public static boolean wildcardMatch(String string, String pattern) { int i = 0; int j = 0; int starIndex = -1; int iIndex = -1; while (i < string.length()) { if (j < pattern.length() && (pattern.charAt(j) == '?' || pattern.charAt(j) == string .charAt(i))) { ++i; ++j; } else if (j < pattern.length() && pattern.charAt(j) == '*') { starIndex = j; iIndex = i; j++; } else if (starIndex != -1) { j = starIndex + 1; i = iIndex + 1; iIndex++; } else { return false; } } while (j < pattern.length() && pattern.charAt(j) == '*') { ++j; } return j == pattern.length(); } }