public final class StringMatcher
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
StringMatcher.Position
Start and end positions of a shortest match found by
find(String, int, int). |
| Constructor and Description |
|---|
StringMatcher(java.lang.String pattern,
boolean ignoreCase,
boolean ignoreWildCards)
StringMatcher constructor takes in a String object that is a simple pattern.
|
| Modifier and Type | Method and Description |
|---|---|
StringMatcher.Position |
find(java.lang.String text,
int start,
int end)
Finds the first occurrence of the pattern between
start (inclusive)
and end (exclusive). |
boolean |
match(java.lang.String text)
Determines whether the given
text matches the pattern. |
boolean |
match(java.lang.String text,
int start,
int end)
Determines whether the given sub-string of
text from start
(inclusive) to end (exclusive) matches the pattern. |
java.lang.String |
toString() |
void |
usePrefixMatch()
Configures this
StringMatcher to also match on prefix-only matches. |
public StringMatcher(java.lang.String pattern,
boolean ignoreCase,
boolean ignoreWildCards)
Literal '*' and '?' characters must be escaped in the pattern e.g., "\*" means literal "*", etc.
The escape character '\' is an escape only if followed by '*', '?', or '\'. All other occurrences are taken literally.
If invoking the StringMatcher with string literals in Java, don't forget escape characters are represented by "\\".
usePrefixMatch()
is used, in which case it always matches.
pattern - the pattern to match text against, must not be nullignoreCase - if true, case is ignoredignoreWildCards - if true, wild cards and their escape sequences are
ignored (everything is taken literally).java.lang.IllegalArgumentException - if pattern == nullpublic void usePrefixMatch()
StringMatcher to also match on prefix-only matches.
If the matcher was created with ignoreWildCards == true, any wildcard
characters in the pattern will still be matched literally.
If the pattern is empty, it will match any text.
public StringMatcher.Position find(java.lang.String text, int start, int end)
start (inclusive)
and end (exclusive).
If wildcards are enabled: If the pattern contains only '*' wildcards a full match is reported, otherwise leading and trailing '*' wildcards are ignored. If the pattern contains interior '*' wildcards, the first shortest match is returned.
text - the String object to search in; must not be nullstart - the starting index of the search range, inclusiveend - the ending index of the search range, exclusiveStringMatcher.Position object for the match found, or null if
there's no match or the text range to search is empty (end <=
start). If the pattern is empty, the position will describe a
null-match in the text at start
(getStart() == getEnd() == start).java.lang.IllegalArgumentException - if text == nullpublic boolean match(java.lang.String text)
text matches the pattern.text - String to match; must not be nulltrue if the whole text matches the pattern;
false otherwisejava.lang.IllegalArgumentException - if text == nullpublic boolean match(java.lang.String text,
int start,
int end)
text from start
(inclusive) to end (exclusive) matches the pattern.text - String to match in; must not be nullstart - start index (inclusive) within text of the sub-string to
matchend - end index (exclusive) within text of the sub-string to
matchtrue if the given slice of text matches the pattern;
false otherwisejava.lang.IllegalArgumentException - if text == nullpublic java.lang.String toString()
toString in class java.lang.Object