Minreg the Cat

From Esolang
Jump to navigation Jump to search

Minreg the Cat (short for "Minimal Regex: the Concatenative") is a variant of Regex, created by the UOPL (Union of User:Olus2000, User:Pro465, and User:LyricLy) in 2024.

pro465 came up with the idea (concatenative regex) inspired by discussion about regex on the esolangs discord server. And his laziness while implementing it led to it being minimal.

olus came up with most of the concatenative variations of regex commands (albeit with a little help from the rest).

lyricly provided constructive criticisms of every single iteration. She also created the semantics of the final iteration of , (see below).

Working

each instruction modifies a matcher, which is basically a tree which matches a specific set of strings according to its contents. note the appending means adding the thing to the matcher tree's list of children, and popping means removing the last element of the list, which makes it effectively a stack.

Instruction Meaning
. appends a matcher that matches any character.
\ appends a matcher that matches the next character in the string and skips it.
, pops the last 2 children of the tree and appends a matcher that only matches if the first and the second child match in sequence.
| pops the last 2 children of the tree and appends a matcher that matches if at least 1 of the children matches.
* pops the last child of the tree and appends a matcher that matches 0 or more of the child.
Any other character appends a matcher that matches the character in question.

Once the expression is fully evaluated, it results in a matcher, which can be used to test if it matches with strings like normal Regex.

Examples

ab and ab, both match only ab.

ab| matches a and/or b.

c* matches , c, cc, etc.

ab* matches a, ab, abb, etc.

ab,* matches , ab, abab, etc.

ab,*cd|,* matches , abccd, ababcabdd, etc.

Implementation

in Rust: Minreg the Cat/minreg.rs