MYR(REGEX)

πŸ“¦ version 0.3.1, in nixos 26.05, nixpkgs unstable

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 property
  • Lu, Uppercase_Letter β€” Uppercase letter unicode property
  • Ll, Lowercase_Letter β€” Lowercase letter unicode property
  • Lt, Titlecase_Letter β€” Titlecase letter unicode property
  • N, Number β€” Number unicode property
  • Z, Separator β€” Any separator character unicode property
  • Zs, 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