MYR(REGEX)
okay so welcome to MYR(REGEX) π β yes bestie, the manual name is literally right there, we're folding it in like a cute lil ribbon π. This is the group-chat translation: every detail stays, only the vibe gets a glow-up. no cap.
π NAME π
regex myr-regex β that's the name, periodt. π
πΈ LIBRARY πΈ
regex β that's the library, bestie. π«Ά
β¨ SYNOPSIS β¨
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)
π DESCRIPTION π
The regex library gives you functions for compiling and evaluating regular expressions, as described later in this document, or in myr-regex(7). iykyk π¦
regex.compile takes a string describing a regex and tries to compile it. If the regex is valid and there were no error conditions encountered during compilation, you get std.Success regex#. If compilation failed, you get std.Failure regex.status, where regex.status is a failure code. slay when it works, sob when it doesn't π
regex.dbgcompile is identical to regex.compile, however, it will print debugging information as it compiles, and each time the regex is evaluated. debug girlie behavior, honestly iconic β¨
regex.exec takes the regex passed to it and evaluates 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. whole string or it doesn't count, bestie π
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. so it's giving "look around, she's in there somewhere" π₯
π¦ REGEX SYNTAX π¦
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:
- Matches a single unicode character β that's literally the line, bestie, no key shown π mystery metachar energy
^β Matches the beginning of a line. Does not consume any characters. zero snack, all vibe$β Matches the end of a line. Does not consume any characters. same zero-snack situation*β Matches any number of repetitions of the preceding regex fragment. infinite-ish repetition era*?β Reluctantly matches any number of repetitions of the preceding regex fragment. reluctant queen+β Matches one or more repetitions of the preceding regex fragment. at least one, periodt+?β Reluctantly matches one or more repetitions of the preceding regex fragment. one or more but shy about it?β Matches zero or one of the preceding regex fragment. maybe yes, maybe no
In order to match a literal metacharacter, it needs to be preceded by a '\' character. escape it or it's gonna act up π
The following character classes are supported:
\dβ ASCII digits\Dβ Negation of ASCII digits\xβ ASCII Hex digits\Xβ Negation of ASCII Hex digits\sβ ASCII spaces\Sβ Negation of ASCII spaces\wβ ASCII word characters\Wβ Negation of ASCII word characters\hβ ASCII whitespace characters\Hβ Negation of ASCII whitespace characters\pX,\p{X}β Characters with unicode property'X'\PX,\P{X}β Negation of characters with unicode property'X'
Unicode properties that are supported are listed below:
L,Letterβ Unicode letter propertyLu,Uppercase_Letterβ Uppercase letter unicode propertyLl,Lowercase_Letterβ Lowercase letter unicode propertyLt,Titlecase_Letterβ Titlecase letter unicode propertyN,Numberβ Number unicode propertyZ,Separatorβ Any separator character unicode propertyZs,Space_Separatorβ Space separator unicode property
π EXAMPLE π
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")
;;
}
π FILES π
The source code for this compiler is available from git://git.eigenstate.org/git/ori/libregex.git β go git it, bestie πΈ
π SEE ALSO π
6m(1) β the see-also bestie β¨
π BUGS π
This code is insufficiently tested. not me saying "we're so brave" π
This code does not support all of the regex features that one would expect. expectation vs. reality, fr fr π
okay that's the whole MYR(REGEX) moment β page 1, MYR(REGEX), signing off with a little sparkle β¨π no cap, go compile something cute. ππ¦
π¦ where this page comes from
- nixos 26.05: myrddin 0.3.1
- nixpkgs unstable: myrddin 0.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms