Here you can find the source of wildCardMatch(String text, String pattern)
Parameter | Description |
---|---|
text | example: helloworld |
pattern | example: hell*world |
public static boolean wildCardMatch(String text, String pattern)
//package com.java2s; public class Main { /**/*from www . j a v a 2 s . co m*/ * test the text match the wild char "*" * @param text example: helloworld * @param pattern example: hell*world * @return * @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a> * @since 2015-4-8 */ public static boolean wildCardMatch(String text, String pattern) { if (pattern == null || pattern.length() < 1 || "*".equals(pattern)) { return true; } if (text == null || text.length() < 1) { return false; } String[] cards = pattern.split("\\*"); for (String card : cards) { int idx = text.indexOf(card); if (idx == -1) { return false; } text = text.substring(idx + card.length()); } return true; } }