22. Regular expression library¶
The experimental REGEX module implement regular expression parser and pattern matching functionality.
Currently its in very early stage and implements only very few basic regex operations.
All functions and symbols are in “regex” module, use require to get access to it.
require daslib/regex
22.1. Type aliases¶
-
CharSet = uint[8]
¶
Bit array which represents an 8-bit character set.
-
MaybeReNode is a variant type
¶
value |
|
nothing |
void? |
Single regular expression node or nothing.
22.2. Enumerations¶
-
ReOp
¶
Char |
0 |
Set |
1 |
Any |
2 |
Eos |
3 |
Group |
4 |
Plus |
5 |
Star |
6 |
Question |
7 |
Concat |
8 |
Union |
9 |
Type of regular expression operation.
-
ReNode
¶
ReNode fields are
op |
|
id |
int |
fun2 |
function<(regex: regex::Regex ;node: regex::ReNode ?;str:uint8? const):uint8?> |
at |
range |
text |
string |
textLen |
int |
all |
array< regex::ReNode ?> |
left |
|
right |
|
subexpr |
|
next |
|
cset |
|
index |
int |
tail |
uint8? |
Single node in regular expression parsing tree.
-
Regex
¶
Regex fields are
root |
|
match |
uint8? |
groups |
array<tuple<range;string>> |
earlyOut |
|
canEarlyOut |
bool |
Regular expression.
22.3. Compilation and validation¶
-
is_valid
(re: Regex)¶
is_valid returns bool
argument |
argument type |
---|---|
re |
|
returns true if enumeration compiled correctly
-
regex_compile
(re: Regex; expr: string const)¶
regex_compile returns bool
argument |
argument type |
---|---|
re |
|
expr |
string const |
Compile regular expression. Validity of the compiled expression is checked by is_valid.
-
regex_compile
(expr: string const)
regex_compile returns regex::Regex
argument |
argument type |
---|---|
expr |
string const |
Compile regular expression. Validity of the compiled expression is checked by is_valid.
-
regex_compile
(re: Regex)
regex_compile returns regex::Regex
argument |
argument type |
---|---|
re |
|
Compile regular expression. Validity of the compiled expression is checked by is_valid.
-
regex_debug
(regex: Regex const)¶
argument |
argument type |
---|---|
regex |
regex::Regex const |
Prints regular expression and its related information in human readable form.
-
debug_set
(cset: CharSet)¶
argument |
argument type |
---|---|
cset |
|
Prints character set in human readable form.
22.4. Access¶
-
regex_group
(regex: Regex const; index: int const; match: string const)¶
regex_group returns string
argument |
argument type |
---|---|
regex |
regex::Regex const |
index |
int const |
match |
string const |
Returns string for the given group index and match result.
-
regex_foreach
(regex: Regex; str: string const; blk: block<(at:range const):bool> const)¶
argument |
argument type |
---|---|
regex |
|
str |
string const |
blk |
block<(at:range const):bool> const |
Iterates through all matches for the given regular expression in str.