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 exactlym
back-to-back matches ofα
- A match of
α{m,n}
consists of at leastm
but at mostn
back-to-back matches ofα
- A match of
α{m,}
consists ofm
or more back-to-back matches ofα
- A match of
α{,n}
consists of at mostn
back-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"