Java Utililty Methods Wildcard Match

List of utility methods to do Wildcard Match

Description

The list of methods to do Wildcard Match are organized into topic(s).

Method

booleanwildCardMatch(final String needle, final String haystack)
Checks to see if needle matches haystack, where needle uses special characters known as wildcards.
char[] wildcard = needle.toCharArray(), string = haystack.toCharArray();
int str = 0, wil = 0;
for (; wil < wildcard.length; wil++) {
    char wild = wildcard[wil];
    if (wild == '\\') {
        wil++;
        if (wildcard[wil] != string[str])
            return false;
...
booleanwildcardMatch(final String pattern, final int patternIndex, final String value, final int valueIndex)
Performs a match operation using wildcards.
int tmpPatternIndex = patternIndex;
int tmpValueIndex = valueIndex;
while (tmpPatternIndex < pattern.length()) {
    if (SINGLE_TOKEN == pattern.charAt(tmpPatternIndex)) {
        tmpPatternIndex += 1;
        if (tmpValueIndex < value.length()) {
            tmpValueIndex += 1;
        } else {
...
booleanwildcardMatch(final String text, final String wildcard)
Return true if text matches with entered wildcard pattern.
if (text == null && wildcard == null)
    return true;
String wildcardRegex = wildcard;
if (wildcard != null) {
    wildcardRegex = wildcardRegex.replaceAll(ANY_SYMBOL, ANY_SYMBOL_REGEXP_REPLACEMENT);
    wildcardRegex = wildcardRegex.replaceAll(ANY_DOT_SYMBOLS, ANY_DOT_SYMBOL_REGEXP_REPLACEMENT);
    wildcardRegex = wildcardRegex.replaceAll(ANY_SYMBOLS_SET, ANY_SYMBOLS_SET_REGEXP_REPLACEMENT);
return regexMatch(text, wildcardRegex);
booleanwildcardMatch(String input, String pattern)
Tries to match input with pattern.
String regex = pattern.replace("?", ".?").replace("*", ".*?");
return input.matches(regex);
booleanwildcardMatch(String pattern, String name)
Match pattern against name, where pattern may contain wildcards ('*').
return wildcardMatch(pattern, name, 0, 0, pattern.length(), name.length());
booleanwildcardMatch(String pattern, String string)
wildcard Match
int stringLength = string.length();
int stringIndex = 0;
for (int patternIndex = 0; patternIndex < pattern.length(); ++patternIndex) {
    char c = pattern.charAt(patternIndex);
    if (c == '*') {
        while (stringIndex < stringLength) {
            if (wildcardMatch(pattern.substring(patternIndex + 1), string.substring(stringIndex))) {
                return true;
...
booleanwildcardMatch(String string, String pattern)
wildcard Match
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;
...
booleanwildCardMatch(String text, String pattern)
Performs a wildcard comparison between two strings, where pattern contains the string with wildcards and textString[] 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;
booleanwildCardMatch(String text, String pattern)
Returns if the given text matches the given search expression.
if (pattern == null || pattern.length() == 0) {
    return true;
if (pattern.length() == 1 && pattern.charAt(0) == '*') {
    return true;
if (text == null || text.length() == 0) {
    return false;
...
booleanwildCardMatch(String text, String pattern)
wild Card Match
String[] cards = pattern.split("\\*");
for (int i = 0; i < cards.length; i++) {
    System.out.println(cards[i]);
for (String card : cards) {
    int idx = text.indexOf(card);
    if (idx == -1) {
        return false;
...