MYR(REGEX) | MYR(REGEX) |
regex myr-regex
regex
use regex const compile : (re : byte[:] ->
std.error(regex#, status)) const dbgcompile : (re : byte[:] ->
std.error(regex#, status)) const free : (re : regex# -> void)
const exec : (re : regex#, str : byte[:] -> bool) const search :
(re : regex#, str : byte[:] -> bool)
The regex library provides functions for compiling and evaluating regular expressions, as described later in this document, or in myr-regex(7).
regex.compile will take a string describing a regex, and will attempt to compile it, returing `std.Success regex# if the regex is valid, and there were no error conditions encountered during compilation. If the compilation failed, `std.Failure regex.status will be returned, where regex.status is a failure code.
regex.dbgcompile is identical to regex.compile, however, it will print debugging information as it compiles, and each time the regex is evaluated.
regex.exec will take the regex passed to it, and evaluate it over the text provided, returning the `std.Some matches, or `std.None if there were no matches found. The matches must span the whole string.
regex.search is similar to regex.exec, but it will attempt to find a match somewhere within the string, instead of attempting to find a match spanning the whole string.
The grammar used by libregex is below:
regex : altexpr
altexpr : catexpr ('|' altexpr)+
catexpr : repexpr (catexpr)+
repexpr : baseexpr[*+?]
baseexpr : literal
| charclass
| charrange
| escaped
| '.'
| '^'
| '$'
| '(' regex ')'
charclass : see below
charrange : '[' (literal('-' literal)?)+']'
The following metacharacters have the meanings listed below:
In order to match a literal metacharacter, it needs to be preceded by a '\' character.
The following character classes are supported:
Unicode properties that are supported are listed below:
use std
use regex
const main = {
var i
match regex.compile(pat)
| `std.Ok re:
match regex.exec(re, text)
| `std.Some matches:
for i = 0; i < matches.len; i++
std.put("Match {}: {}0, i, matches[i])
;;
| `std.None: std.put("Text did not match0)
;;
| `std.Err err:
std.put("failed to compile regex")
;;
}
The source code for this compiler is available from git://git.eigenstate.org/git/ori/libregex.git
6m(1)
This code is insufficiently tested.
This code does not support all of the regex features that one would expect.
1 | x86_64 |