Matcher

Methods
24
Fields
None

Getting one

Pattern.compile(…):matcher(…)

Methods

MethodReturnsDescription
group(string)string?Named group name's text, or nil.
start(string)numberWhere named group name starts, or -1.
end_(string)numberend(name), spelled end_ because Luau reserves end: where named group name ends, or -1.
find()boolean(Matcher) -> boolean: The next match: from the region start, or after the previous match.
find(number)boolean
matches()booleanWhether the whole region matches.
lookingAt()booleanWhether a match starts at the region start.
reset()Matcher(Matcher) -> Matcher: Forget the position and the region; this matcher.
reset(string)Matcher
replaceAll(string)stringThe text with every match replaced ($1, ${name}, \$ in replacement). Leaves the matcher after its last (failed) find.
replaceFirst(string)stringThe text with the first match replaced. Leaves the matcher on that match.
appendReplacement({string}, string)MatcherAppend the text since the last append, then the expanded replacement ($1, ${name}), to sb as one more element; this matcher. sb i…
appendTail({string}){string}Append the rest of the text to sb (a Luau array of parts, as for appendReplacement); sb.
region(number, number)MatcherSearch only start..end (UTF-16 indices); this matcher.
regionStart()numberThe region's start.
regionEnd()numberThe region's end.
hasTransparentBounds()booleanWhether lookaround sees past the region.
useTransparentBounds(boolean)MatcherLet lookaround and \b see past the region (default false); this matcher.
hasAnchoringBounds()booleanWhether ^/$ match at the region's bounds.
useAnchoringBounds(boolean)MatcherLet ^/$ match at the region's bounds (default true); this matcher.
pattern()PatternThe pattern: the very Pattern it was made from (or last given to usePattern).
usePattern(Pattern)MatcherMatch with pattern from here on: the position and region kept, the groups forgotten (group() is nil until the next match, start() sti…
toMatchResult()MatchResultA snapshot of the current match: a MatchResult that shares the text and does not move.
matchResults(){MatchResult}The remaining results: every match left, as a 1-based array of MatchResult snapshots. It is eager: it finds every match now and leaves th…
toString()stringjava.util.regex.Matcher[pattern=.. region=a,b lastmatch=..].
quoteReplacement(string)strings with \ and $ escaped, for a literal replacement.

Returned by

MethodReturnsDescription
Pattern.matcherMatcherA matcher of this pattern over input.

Method details

group

group: (Matcher, string) -> string?

Named group name's text, or nil.

start

start: (Matcher, string) -> number

Where named group name starts, or -1.

end_

end_: (Matcher, string) -> number

end(name), spelled end_ because Luau reserves end: where named group name ends, or -1.

Luau reserves end, so this member is spelled end_; it behaves exactly as end.

find

find: ((Matcher) -> boolean) & ((Matcher, number) -> boolean)

(Matcher) -> boolean: The next match: from the region start, or after the previous match.

(Matcher, number) -> boolean: Reset, then the first match at or after start.

lookingAt

lookingAt: (Matcher) -> boolean

Whether a match starts at the region start.

reset

reset: ((Matcher) -> Matcher) & ((Matcher, string) -> Matcher)

(Matcher) -> Matcher: Forget the position and the region; this matcher.

(Matcher, string) -> Matcher: Match input from the start; this matcher.

replaceAll

replaceAll: (Matcher, string) -> string

The text with every match replaced ($1, ${name}, \$ in replacement). Leaves the matcher after its last (failed) find.

replaceFirst

replaceFirst: (Matcher, string) -> string

The text with the first match replaced. Leaves the matcher on that match.

appendReplacement

appendReplacement: (Matcher, {string}, string) -> Matcher

Append the text since the last append, then the expanded replacement ($1, ${name}), to sb as one more element; this matcher. sb is a Luau array of parts, which table.concat(sb) joins.

appendTail

appendTail: (Matcher, {string}) -> {string}

Append the rest of the text to sb (a Luau array of parts, as for appendReplacement); sb.

region

region: (Matcher, number, number) -> Matcher

Search only start..end (UTF-16 indices); this matcher.

pattern

pattern: (Matcher) -> Pattern

The pattern: the very Pattern it was made from (or last given to usePattern).

usePattern

usePattern: (Matcher, Pattern) -> Matcher

Match with pattern from here on: the position and region kept, the groups forgotten (group() is nil until the next match, start() still the last match's); this matcher.

matchResults

matchResults: (Matcher) -> {MatchResult}

The remaining results: every match left, as a 1-based array of MatchResult snapshots. It is eager: it finds every match now and leaves the matcher after the last (for the first match alone, call find()).

toString

toString: (Matcher) -> string

java.util.regex.Matcher[pattern=.. region=a,b lastmatch=..].

quoteReplacement

quoteReplacement: (string) -> string

s with \ and $ escaped, for a literal replacement.