std::text::regexRegular expression matching.
Compile patterns once and match against multiple strings.
import std::text::regex;
fn main() {
let re = regex.new("[0-9]+");
if re.is_match("abc123") {
let m = re.find("abc123");
println(m); // "123"
}
re.free();
}
newCompile a regular expression pattern.
Panics if the pattern syntax is invalid.
let email_re = regex.new("[a-z]+@[a-z]+\\.[a-z]+");
email_re.free();
PatternA compiled regular expression pattern.
Created by regex.new(pattern). Call free() before the value goes out of
scope; dropping without free() is a resource leak.
CaptureMatchesFlat row-major capture results for captures and find_all_submatch.
Each match row has group_count entries. Group 0 is the whole match and
groups 1..n are capture groups. Missing optional groups are stored as "".
PatternMethodsMethods available on a compiled Pattern.
Test whether the pattern matches anywhere in the input string.
let re = regex.new("^[a-z]+$");
assert(re.is_match("hello"));
re.free();
Ergonomic alias for is_match. Returns true when the pattern matches
anywhere in input. Provided so call sites can read as
pattern.matches(text) โ a one-to-one replacement for the removed
text =~ pattern operator.
Find the first match of the pattern in the input string.
Returns the matched substring, or an empty string if no match.
Replace all occurrences of the pattern with the replacement string.
let re = regex.new("[0-9]+");
let result = re.replace("abc123def456", "N");
// result == "abcNdefN"
re.free();
Find all non-overlapping matches in the input string.
Returns an empty vector when there are no matches.
Return the indexed capture from the first match.
Group 0 is the whole match. Returns None for no match, an invalid
group, or a non-participating optional group.
Return the named capture from the first match.
Returns None for no match, unknown name, or non-participating optional
group.
Return first-match submatches as one flat row.
Return all matches' submatches as row-major flat results.
Clone the compiled pattern, producing an independent copy.
Each clone must be dropped or freed independently.
Canonical release path for Pattern.
Callers MUST invoke free() before the value goes out of scope;
dropping without free() is a resource leak.
CaptureMatchesMethodsMethods available on flat capture results.
Return the number of match rows.
Return true when there are no match rows.
Return the number of groups in each row, including group 0.
Return a capture by match row and group index.
Return group 0 for the requested match row.