REGXY

REGXY is an esoteric programming language by User:Zzo38 based on regular expressions. It has two kinds of command, test and change. The program operates on an input string starting at the top of the program and running each command. On reaching the end it outputs the string. The command syntax and meaning is:


 * test: label/regex/target_label (jumps to the target label if the regex matches)
 * change: label/regex/substitute/ (does a regex substitution and supports backrefs like $1,$2,..)

Examples
Reverse a string:

a/$/_/ b/(.)(.*)_/$2_$1/ c/(.)(.*)_/b d/_//

99-bottles of beer (modified slightly to suit modern implementation):

0/^.*$// a//z9az8az7az6az5az4az3az2az1aza/ b/z([0-9]?)a/x${1}9x${1}8x${1}7x${1}6x${1}5x${1}4x${1}3x${1}2x${1}1x${1}0/ bq/z([0-9]?)a/b rc/x([0-9][0-9]?)/$1 botles uv beer. $1 botles uv beer on the wall, $1 botles uv beer, Take 1 down and pass it around, / rcq/x([0-9][0-9]?)/rc d/^99 botles uv beer. // e/, 0 botles uv beer.*$/, No more botles uv beer on the wall./

Self hosting RegXY to perl implementation:

sanitize/(^|\n)([^\/]*)\+([^\/]*)\/(([^\/]|\\.)*)\/(([^\/]|\\.)*)\/(\n|$)/$1$2_plus$3\/$4\/$6\/$8/ sanitizf/(^|\n)([^\/]*)\+/sanitize sanitizg/(^|\n)([^\/]*)\/(([^\/]|\\.)*)\/([^\/]*)\+([^\/]*)(\n|$)/$1$2\/$3\/$5_plus$6$7/ sanitizh/\+([^\/]*)($|\n)/sanitizg loop/(^|\n)([^\n\/ ]*)\/(([^\/]|\\.)*)\/([^\n\/]*)(\n|$)/$1 l$2: if(\$i =~ m\/$3\/s) { goto l$5; }$6/ looq/(^|\n)([^\n\/ ]*)\/(([^\/]|\\.)*)\/(([^\/]|\\.)*)\/(\n|$)/$1 l$2: \$i =~ s\/$3\/$5\/s;$7/ loor/(^|\n)[^ ]/loop start/^/local \$\/; \$i =<>;\n/ finish/$/\nprint(\$i);/

Implementation
In Perl:

local $/; $i =<>; lsanitize: $i =~ s/(^|\n)([^\/]*)\+([^\/]*)\/(([^\/]|\\.)*)\/(([^\/]|\\.)*)\/(\n|$)/$1$2_plus$3\/$4\/$6\/$8/s; lsanitizf: if($i =~ m/(^|\n)([^\/]*)\+/s) { goto lsanitize; } lsanitizg: $i =~ s/(^|\n)([^\/]*)\/(([^\/]|\\.)*)\/([^\/]*)\+([^\/]*)(\n|$)/$1$2\/$3\/$5_plus$6$7/s; lsanitizh: if($i =~ m/\+([^\/]*)($|\n)/s) { goto lsanitizg; } lloop: $i =~ s/(^|\n)([^\n\/ ]*)\/(([^\/]|\\.)*)\/([^\n\/]*)(\n|$)/$1 l$2: if(\$i =~ m\/$3\/s) { goto l$5; }$6/s; llooq: $i =~ s/(^|\n)([^\n\/ ]*)\/(([^\/]|\\.)*)\/(([^\/]|\\.)*)\/(\n|$)/$1 l$2: \$i =~ s\/$3\/$5\/s;$7/s; lloor: if($i =~ m/(^|\n)[^ ]/s) { goto lloop; } lstart: $i =~ s/^/local \$\/; \$i =<>;\n/s; lfinish: $i =~ s/$/\nprint(\$i);/s; print($i);

External resources

 * Zzo38's directory of REGXY implementation and programs
 * REGXY entry on C2 Wiki