std/regex
Regular expressions with the syntax and the semantics of RE2, written in TorbScript: Regex compiles a pattern once,
and matching runs in time linear in the length of the text - there is no backtracking, so there are no backreferences
and no lookaround, and no pattern can take a program down with a text it was handed. The engine is the same code in
the VM and in a native binary, so both answer the same.
const pattern: Regex = "(?P<key>\w+)=(?P<value>\w+)"
for found in pattern.findAll("a=1 b=2") {
print "{found.named("key")} is {found.named("value")}"
}
A pattern works on characters, and every position it answers is a byte offset into the text, as every position of a
String is. Named groups decode into a type through Decode (RegexMatch.decoded). A literal where a Regex is
expected is compiled by the compiler where it is written, and read verbatim, so \d and {2,4} need no raw.
Modules
std/regex/regex[Regex] and [RegexMatch]: a compiled pattern as a value, and what one match found.std/regex/syntaxThe syntax of a pattern: RE2's, read into a tree of [RegexNode]s.
Everything
- type
GroupRangeWhere a group of a match is: fromstartto right beforeend, as byte offsets. - type
RegexA regular expression with the syntax and the semantics of RE2: it matches in time linear in the length of the text, so it has no backreferences and no lookaround. - type
RegexErrorWhy a text is not a regular expression: what is wrong, and the byte offset in the pattern where it was found. - type
RegexMatchOne match: where it is in the text, and what each group found. - extend
String with From<Regex>A pattern is its text wherever aRegexis written or read:EncodeandDecodego through this pair.