esolang

REXS

Regular expressions written out as nested function calls. The program's output is the regex.

Uellenberg, 2021 · Turing complete: no · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: /^(.*?)!(.*?) PRIVMSG \#(.*?) :(.*)$/

The idea

Uellenberg made REXS in 2021 to make complex regular expressions easier to read and write. Every part of a regex becomes a named call, match("!") for a literal, repeat(0, inf) around what repeats and group() around a capture. Calls with a body take braces, the others end with a semicolon. Running a program prints the regular expression it compiles to.

The machine

CallWrites
match("text"); match(ANY);The text, escaped, or a class such as . or \d
assert(START); assert(END);^ or $, and \b \B for word boundaries
group() { }A capturing group
repeat(min, max) { }The body repeated; inf for no maximum, nongreedy for the least
set() { } to();A character set such as [a-z]
or() { orpart() { } ... }One of the parts
before() { } after() { }A lookbehind or lookahead, with not for the negative
backref(n); flag(i);A back reference; a flag after the closing slash

The IRC example is the only output it shows. It escapes # and leaves space, ! and : alone. For the other calls this implementation writes the plainest regex.

Example

The IRC example, with each group on one line.

The IRC example, with each group on one line. It takes a message such as name!email PRIVMSG #channel :message apart into four groups.

Expected: /t/

A set, a repeat and a flag, as this implementation writes them.

Expected: /[a-z]\d+/i

Further

Also in Rewriting

Write your own in Run Convert a program from REXS

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: rexs.

Command line

shib run rexs -e 'match("t");'
shib manual rexs

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/rexs.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org