Minreg the Cat
A regex written in postfix. Each character adds a matcher or joins the last ones it added.
Olus2000, Pro465 and LyricLy, 2024 · Turing complete: no · ●●○ moderate · esolangs.org
Tested with 15 known programs · Test method
Run it
The idea
The name is short for Minimal Regex, the Concatenative. Olus2000, Pro465 and LyricLy made it together in 2024, after a discussion about regex on the esolangs Discord server. Pro465 had the idea, and the specification says his laziness in writing the interpreter kept it minimal.
Read the story
A pattern is built the way a stack language computes. ab| is a or b, ab,* is ab repeated, and ab,*cd|,* is what a usual regex writes as ((ab)*(c|d))*. There are no brackets, because the order of the characters says it all.
The machine
The program builds a list of matchers from left to right. The list as a whole matches its matchers one after the other, so ab and ab, mean the same.
| Char | Does |
|---|---|
. | Add a matcher for any one character |
\ | Add a matcher for the next character of the program |
, | Take the last two and add their sequence |
| | Take the last two and add a choice between them |
* | Take the last one and add zero or more of it |
| any other | Add a matcher for that character |
The input is the string to test, all of it. The run prints 1 when the pattern matches the whole input and 0 when it does not. Every pattern is a finite automaton, so every test ends.
Example
The longest example, on one of the strings the specification names and on one it cannot match.
The longest example, on one of the strings the specification names and on one it cannot match.
ab* stars only the b, and ab,* stars the pair.
Patterns it teaches
- Concatenative: a pattern is written one piece after another and joined afterwards, as in a stack language.
Further
See also
Also in Functional and concatenative
Write your own in Run Convert a program from Minreg the Cat
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: minreg-the-cat.
Command line
shib run minreg-the-cat -e 'ab' --input 'ab'shib manual minreg-the-catSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/minreg-the-cat.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org