is Match(text: string) - > bool- Module
- std.
regex - Receiver
- Regex
- Minimum arity
- 1
- Maximum arity
- 1
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.regex in language mode 5.21.
The current compiler selects std/regex.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1052 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 55 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1052 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 442 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1296 - compiler/crates/topaz_value/src/value/members.rs at
b48527d0a174· 272
Receiver
Regex
Parameter constraints
Regex.isMatch reports whether a match exists anywhere in the input. Regex.find returns Some containing the first match or None() when no match exists. Regex.findAll returns every nonoverlapping match in search order and returns an empty array when no match exists.
Search begins at the earliest Unicode scalar boundary that permits the complete pattern to match. At that position alternatives are tried in pattern order. Greedy repetitions prefer more scalars and lazy repetitions prefer fewer scalars while still allowing the rest of the pattern to match.
After a nonempty match, findAll resumes at its exclusive end. After an empty match, it resumes at the next Unicode scalar boundary. An empty match directly at the end of the preceding nonempty match is skipped and search advances to the next scalar boundary.
An empty pattern visits every scalar boundary, including both ends. The empty input has one boundary and produces one empty match for an empty pattern. Matching never splits the UTF-8 bytes of a scalar.
Regex.split and Regex.replaceAll use the same ordered match sequence as findAll. Repeated calls start a new search and do not retain a cursor. The input string and compiled pattern are unchanged.
The receiver is evaluated once before the positional arguments, which are evaluated once from left to right. Search does not invoke user callbacks or access external state. No match is an ordinary result and does not produce a diagnostic.
Related rule: Search from the left and advance through nonoverlapping matchesResult
The declared result type is bool.
Effects
Failures
Result and effects
LinkReports whether a leftmost-first search finds a match anywhere in the input.
Resolved contracts
LinkRelated entries
LinkSearch from the left and advance through nonoverlapping matches
LinkSearch from the left and advance through nonoverlapping matches
Regex.isMatch reports whether a match exists anywhere in the input. Regex.find returns Some containing the first match or None() when no match exists. Regex.findAll returns every nonoverlapping match in search order and returns an empty array when no match exists.
Search begins at the earliest Unicode scalar boundary that permits the complete pattern to match. At that position alternatives are tried in pattern order. Greedy repetitions prefer more scalars and lazy repetitions prefer fewer scalars while still allowing the rest of the pattern to match.
After a nonempty match, findAll resumes at its exclusive end. After an empty match, it resumes at the next Unicode scalar boundary. An empty match directly at the end of the preceding nonempty match is skipped and search advances to the next scalar boundary.
An empty pattern visits every scalar boundary, including both ends. The empty input has one boundary and produces one empty match for an empty pattern. Matching never splits the UTF-8 bytes of a scalar.
Regex.split and Regex.replaceAll use the same ordered match sequence as findAll. Repeated calls start a new search and do not retain a cursor. The input string and compiled pattern are unchanged.
The receiver is evaluated once before the positional arguments, which are evaluated once from left to right. Search does not invoke user callbacks or access external state. No match is an ordinary result and does not produce a diagnostic.
Why
One ordered match sequence makes searching, splitting, and replacement agree. Advancing after an empty match ensures progress without splitting a Unicode scalar. Boolean search is distinct from extracting Match data and does not introduce regex membership through the in operator.
Source evidence
- compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 115 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 193 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 524 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 548 -
topaz.stdlib.contract.regex-searchatworking-tree - topaz.decision.regex-match-sequence.1 at
topaz.decisi
Choose the first successful alternative at the leftmost position
Linkimport std.regex { Regex }import std.iomatch (Regex.compile("a|ab")) {case Ok(pattern) => {match (pattern.find("zab")) {case Some(found) => io.writeLine("{found.start}:{found.end}:{found.text}")case None() => io.writeLine("no match")}let present = pattern.isMatch("zab")let absent = pattern.isMatch("zzz")io.writeLine("{present}:{absent}")match (pattern.find("zzz")) {case None() => io.writeLine("none")case Some(_) => io.writeLine("present")}let matches = pattern.findAll("zzz")io.writeLine("{matches.length}")}case Err(_) => io.writeLine("compile failed")}
1:2:a true:false none 0
Expected result
Expected result
Execution completes. Exit code 0.
1:2:atrue:falsenone0
Source evidence
- compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 115 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 193 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 524 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 548 -
topaz.stdlib.contract.regex-searchatworking-tree - topaz.decision.regex-match-sequence.1 at
topaz.decisi
Choose a group alternative that allows the complete pattern to match
Linkimport std.regex { Regex }import std.iomatch (Regex.compile("(a|ab)c")) {case Ok(pattern) => {match (pattern.find("abc")) {case Some(found) => io.writeLine(found.text)case None() => io.writeLine("no match")}}case Err(_) => io.writeLine("compile failed")}
abc
Expected result
Expected result
Execution completes. Exit code 0.
abc
Source evidence
- compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 115 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 193 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 524 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 548 -
topaz.stdlib.contract.regex-searchatworking-tree - topaz.decision.regex-match-sequence.1 at
topaz.decisi
Return nonoverlapping matches in input order
Linkimport std.regex { Regex }import std.iomatch (Regex.compile("aa")) {case Ok(pattern) => {for found in (pattern.findAll("aaaaa")) {io.writeLine("{found.start}:{found.end}:{found.text}")}}case Err(_) => io.writeLine("compile failed")}
0:2:aa 2:4:aa
Expected result
Expected result
Execution completes. Exit code 0.
0:2:aa2:4:aa
Source evidence
- compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 115 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 193 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 524 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 548 -
topaz.stdlib.contract.regex-searchatworking-tree - topaz.decision.regex-match-sequence.1 at
topaz.decisi
Visit each boundary for an empty pattern and the empty input
Linkimport std.regex { Regex }import std.iomatch (Regex.compile("")) {case Ok(pattern) => {for found in (pattern.findAll("ab")) {io.writeLine("{found.start}:{found.end}")}io.writeLine("empty input")for found in (pattern.findAll("")) {io.writeLine("{found.start}:{found.end}")}}case Err(_) => io.writeLine("compile failed")}
0:0 1:1 2:2 empty input 0:0
Expected result
Expected result
Execution completes. Exit code 0.
0:01:12:2empty input0:0
Source evidence
- compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 115 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 193 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 524 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 548 -
topaz.stdlib.contract.regex-searchatworking-tree - topaz.decision.regex-match-sequence.1 at
topaz.decisi
Skip an empty match directly after a nonempty match
Linkimport std.regex { Regex }import std.iomatch (Regex.compile("a*")) {case Ok(pattern) => {for found in (pattern.findAll("ab")) {io.writeLine("{found.start}:{found.end}:{found.text}")}}case Err(_) => io.writeLine("compile failed")}
0:1:a 2:2:
Expected result
Expected result
Execution completes. Exit code 0.
0:1:a2:2:
Source evidence
- compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 115 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 193 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 524 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 548 -
topaz.stdlib.contract.regex-searchatworking-tree - topaz.decision.regex-match-sequence.1 at
topaz.decisi
Return no match after scanning a longer valid input
Linkimport std.regex { Regex }import std.iolet mut text = "a"for step in (0 .. 17) {text = text + text}match (Regex.compile("z")) {case Ok(pattern) => io.writeLine("{pattern.isMatch(text)}")case Err(_) => io.writeLine("compile failed")}
false
Expected result
Expected result
Execution completes. Exit code 0.
false
Source evidence
- compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 115 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/value/regex.rs at
912a5e86e1f9· 193 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 524 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 548 -
topaz.stdlib.contract.regex-searchatworking-tree - topaz.decision.regex-match-sequence.1 at
topaz.decisi