Home

javautilregexMatcher

java.util.regex.Matcher is the runtime engine used to perform regex operations against a character sequence according to a compiled Pattern. A Matcher is created by Pattern.compile(regex).matcher(input) and the same Pattern can produce multiple Matcher instances. The Matcher maintains state about the current input region, the results of the last match, and any captured groups.

Key operations include find(), which searches for the next subsequence that matches the pattern; matches(), which

Region and boundaries can be controlled with region(int start, int end) to limit the search, and find(int

Additional features include reset() to reuse the same Matcher with a new input, and toMatchResult() to obtain

See also Pattern and the java.util.regex package for related classes and utilities. Example usage typically involves

attempts
to
match
the
entire
region;
and
lookingAt(),
which
attempts
to
match
from
the
region’s
start.
After
a
successful
match,
group(),
group(int),
and
groupCount()
provide
access
to
captured
substrings,
with
group(0)
representing
the
entire
match.
start()
and
end()
report
the
bounds
of
the
overall
match
or
of
a
specific
group.
start)
to
restart
searching
from
a
given
position.
Replacement
and
construction
utilities
include
replaceAll(String)
and
replaceFirst(String)
for
producing
a
new
string
with
substitutions,
as
well
as
appendReplacement
and
appendTail
for
incremental
result
building.
a
read-only
view
of
the
current
match.
Note
that
Matcher
is
not
thread-safe;
it
should
not
be
shared
across
threads.
compiling
a
Pattern,
obtaining
a
Matcher
for
an
input,
iterating
with
find(),
and
retrieving
groups
as
needed.