Package de.unkrig.lfr.core
Interface Matcher
- All Superinterfaces:
Matcher
,MatchResult
Adds some "advanced" methods to the
Matcher
interface.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Pre-parsing a "replacement string" saves considerable overhead compared to repeatedly callingMatcher.appendReplacement(Appendable, String)
. -
Method Summary
Modifier and TypeMethodDescriptioncompileReplacement
(String replacement) Pre-compiles a replacement string for later use byMatcher.appendReplacement(Appendable, String)
,Matcher.replaceAll(String)
andMatcher.replaceFirst(String)
.int
count
(int number) Returns, after a successful match, the value of the designated "capturing quantifier".Methods inherited from interface de.unkrig.ref4j.Matcher
appendReplacement, appendTail, end, end, end, find, find, group, group, group, groupCount, hasAnchoringBounds, hasTransparentBounds, hitEnd, lookingAt, matches, pattern, region, regionEnd, regionStart, replaceAll, replaceAll, replaceFirst, replaceFirst, requireEnd, reset, reset, results, start, start, start, toMatchResult, toString, useAnchoringBounds, usePattern, useTransparentBounds
-
Method Details
-
compileReplacement
Pre-compiles a replacement string for later use byMatcher.appendReplacement(Appendable, String)
,Matcher.replaceAll(String)
andMatcher.replaceFirst(String)
.Supports the following JRE6-compatible constructs:
-
\
x
x - The character x, literally.
$
n-
The value of the nth capturing group, or
""
if that group is not set.
Supports the following JRE7-compatible constructs:
${
name}
-
The value of the named capturing group "name", or
""
if that group is not set.
Supports the following additional constructs:
${
expression}
-
The value of the expression. The named groups of the pattern are available as expression
variables; the matcher is available as variable "m". For the expression syntax, see
Parser
.
-
-
count
int count(int number) Returns, after a successful match, the value of the designated "capturing quantifier". A "capturing quantifier" has the form "{m,n}
", where the comma andn
are optional.Capturing quantifier numbers start at zero, and increase left-to-right.
Example:
The regex is
"a{1,}b{1,}c{1,}"
, the subject string is" abc aabbcc abbccc "
. There are three matches, andcount(int)
returns the following values:Match # count(0)
count(1)
count(2)
1 1 1 1 2 2 2 2 3 1 2 3 The return value is undefined if there was no previous match, or if the quantifier was not executed during the match.
-
quoteReplacement
- Specified by:
quoteReplacement
in interfaceMatcher
- See Also:
-