public class WildcardMatch extends Object
Wildcard characters can be escaped (default: by an '\').
This class always matches for the whole word.
Examples:
WildcardMatch wm = new WildcardMatch(); System.out.println(wm.match("CfgOptions.class", "C*.class")); // true System.out.println(wm.match("CfgOptions.class", "?gOpti*c?as?")); // false System.out.println(wm.match("CfgOptions.class", "??gOpti*c?ass")); // true System.out.println(wm.match("What's this?", "What\*\?")); // true System.out.println(wm.match("What's this?", "What*?")); // true System.out.println(wm.match("A \\ backslash", "\*\\\?back*")); // true
Constructor and Description |
---|
WildcardMatch() |
WildcardMatch(char singleChar,
char multipleChars) |
Modifier and Type | Method and Description |
---|---|
boolean |
getCaseSensitive()
Returns the current state of case sensitivity.
|
char |
getEscapeChar()
Returns the character used to escape the wildcard functionality of a
wildcard character.
|
char |
getMultipleWildcardChar()
Returns the character used to specify any amount of characters.
|
char |
getSingleWildcardChar()
Returns the character used to specify exactly one character.
|
boolean |
match(String s,
String pattern)
Matches a string against a pattern with wildcards.
|
void |
setCaseSensitive(boolean caseSensitive)
Makes pattern matching case insensitive.
|
void |
setEscapeChar(char escapeChar)
Sets the new character to be used as an escape character, overriding the
the default of '\'.
|
void |
setWildcardChars(char singleChar,
char multipleChars)
Sets new characters to be used as wildcard characters, overriding the
the default of '?' for any single character match and '*' for any
amount of characters, including 0 characters.
|
public WildcardMatch()
public WildcardMatch(char singleChar, char multipleChars)
public void setWildcardChars(char singleChar, char multipleChars)
singleChar
- The char used to match exactly ONE character.multipleChars
- The char used to match any amount of characters
including o characters.public void setEscapeChar(char escapeChar)
escapeChar
- The char used to match escape wildcard characters.public char getSingleWildcardChar()
public char getMultipleWildcardChar()
public char getEscapeChar()
public void setCaseSensitive(boolean caseSensitive)
caseSensitive
- false for case insensitivity. Default is case
sensitive match.public boolean getCaseSensitive()
public boolean match(String s, String pattern)
s
- The string, in which the search should be performed.pattern
- The search pattern string including wildcards.Copyright © 1997–2015 NIH. All rights reserved.