public final class Matcher extends Object implements MatchResult
Modifier and Type | Method and Description |
---|---|
int |
end()
Returns the offset after the last match.
|
int |
end(int group)
Returns the index after the subsequence captured by the given group.
|
boolean |
find()
Find next match (if any) in the string.
|
boolean |
find(int ofs)
Find next match (if any) in the string.
|
String |
group()
Returns the input subsequence captured by the previous match.
|
String |
group(int group)
Returns the input sequence captured by the given group.
|
String |
group(String name)
Returns the input sequence captured by the named capturing group.
|
int |
groupCount()
Returns the number of capture groups.
|
boolean |
lookingAt()
Returns true if the string has at least one match by the pattern.
|
boolean |
matches()
Returns true if and only if the string is matched by the pattern.
|
Pattern |
pattern()
Returns the regex machine used by this matcher.
|
String |
replaceAll(String replacement)
Replaces every matched subsequence.
|
String |
replaceFirst(String replacement)
Replaces the first matched subsequence.
|
Matcher |
reset()
Reset this matcher.
|
Matcher |
reset(String str)
Reset this matcher with a new input string.
|
int |
start()
Returns the offset of the last match.
|
int |
start(int group)
Returns the start index of the subsequence captured by the given group.
|
MatchResult |
toMatchResult()
Returns the match state of this matcher.
|
Matcher |
usePattern(Pattern p)
Changes the pattern used by this matcher.
|
public Pattern pattern()
public Matcher usePattern(Pattern p)
p
- new patternpublic boolean matches()
public boolean lookingAt()
public boolean find()
public boolean find(int ofs)
ofs
- offset indicating where to start the searchpublic Matcher reset()
public Matcher reset(String str)
str
- new patternpublic int groupCount()
groupCount
in interface MatchResult
public String group()
group
in interface MatchResult
public String group(int group) throws IndexOutOfBoundsException, IllegalStateException
group
in interface MatchResult
group
- group indexIndexOutOfBoundsException
- If there is no capturing group in the pattern with the given indexIllegalStateException
- If no match has yet been attempted, or if the previous match operation failedpublic String group(String name)
name
- group namepublic int start()
start
in interface MatchResult
public int start(int group) throws IndexOutOfBoundsException, IllegalStateException
start
in interface MatchResult
group
- group indexIndexOutOfBoundsException
- If there is no capturing group in the pattern with the given indexIllegalStateException
- If no match has yet been attempted, or if the previous match operation failedpublic int end()
end
in interface MatchResult
public int end(int group) throws IndexOutOfBoundsException, IllegalStateException
end
in interface MatchResult
group
- group indexIndexOutOfBoundsException
- If there is no capturing group in the pattern with the given indexIllegalStateException
- If no match has yet been attempted, or if the previous match operation failedpublic String replaceAll(String replacement)
replacement
- used to replace matching datapublic String replaceFirst(String replacement)
replacement
- used to replace the matching datapublic MatchResult toMatchResult()