RegEx Syntax #
We currently use a very simplified form for regular expression syntax.
Operators:
- A match of
α|βconsists of either a match ofαor a match ofβ - A match of
αβconsists of a match ofαfollowed by a match ofβ - A match of
α?consists of at most one match ofα - A match of
α*consists of zero or more back-to-back matches ofα - A match of
α+consists of one or more back-to-back matches ofα - A match of
α{m}consists of exactlymback-to-back matches ofα - A match of
α{m,n}consists of at leastmbut at mostnback-to-back matches ofα - A match of
α{m,}consists ofmor more back-to-back matches ofα - A match of
α{,n}consists of at mostnback-to-back matches ofα - A match of
(α)consists of a match ofα
These are listed from lowest to highest precedence.
Character matching:
.matches any character.- A single character matches itself with the exception of the special characters:
.,?,*,+,|,\,(,),{,},[,]. These special characters can be matched by preceding them with an escape character\. [c]matches one character from the classc.[^c]matches one character not in the classc.
Character classes support single characters and character ranges. The special characters -,
[, \, ] must be preceded by an escape character \ within a class.
Compiles a regex from a string, returns none on faiure
Equations
- Parser.RegEx.compile? s = match (Parser.RegEx.re0✝ <* Parser.endOfInput).run s.toSubstring with | Parser.Result.ok a r => some r | Parser.Result.error a a_1 => none
Instances For
Compiles a regex from a string, panics on faiure
Equations
- Parser.RegEx.compile! s = match Parser.RegEx.compile? s with | some r => r | none => panicWithPosWithDecl "Parser.RegEx.Compile" "Parser.RegEx.compile!" 179 12 "invalid regular expression"