Java Wildcard Match wildcardMatch(String input, String pattern)

Here you can find the source of wildcardMatch(String input, String pattern)

Description

Tries to match input with pattern.

License

Open Source License

Parameter

Parameter Description
input The string to be checked
pattern The pattern to match

Return

true if the input matches the pattern, false otherwise.

Declaration

public static boolean wildcardMatch(String input, String pattern) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// www.j  a v  a2  s  .c o m
     * Tries to match <b>input</b> with <b>pattern</b>. The pattern can use the
     * "*" and "?" globs to match any-char-sequence and any-char respectively.
     *
     * @param input   The string to be checked
     * @param pattern The pattern to match
     * @return <b>true</b> if the <b>input</b> matches the <b>pattern</b>,
     *         <b>false</b> otherwise.
     */
    public static boolean wildcardMatch(String input, String pattern) {
        String regex = pattern.replace("?", ".?").replace("*", ".*?");
        return input.matches(regex);
    }
}

Related

  1. wildCardMatch(final String needle, final String haystack)
  2. wildcardMatch(final String pattern, final int patternIndex, final String value, final int valueIndex)
  3. wildcardMatch(final String text, final String wildcard)
  4. wildcardMatch(String pattern, String name)
  5. wildcardMatch(String pattern, String string)
  6. wildcardMatch(String string, String pattern)
  7. wildCardMatch(String text, String pattern)