~
{2`
$`
T01`p`_p
The leading linefeed is significant.
Try it online!
Explanation
Stage 1: Substitution
~
We start by replacing the empty (non-existent) input with a single ~
.
Stage 2: Substitution
{2`
$`
The regex of this substitution is still empty, since the `
separates configuration from regex and {2
is therefore just the configuration. The {
indicates that the remaining two stages should be run in a loop until they stop changing the output. The 2
indicates that this specific stage has a limit of 2
, meaning that only the first two matches of the regex will be replaced. Since the regex is empty, that means we get an empty match in front of the string and an empty match after the first character.
This match is replaced with the prefix $`
which refers to everything in front of the match. For the first match, there is nothing in front of it, so this doesn't insert anything, but for the second match, there is the leading character in front of it, which therefore gets duplicated.
Stage 3: Transliteration
T01`p`_p
Here, T
activates transliteration mode, and 0
and 1
are limits (where 0
just means "don't set this limit"). Together, they mean "transliterate only the first character in the string". The actual transliteration maps from p
to _p
. Here, p
expands to the printable ASCII characters and _
means "remove" this character, so the expanded lists look like this:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
_ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
That means spaces get removed and all other characters get decremented by one.
To see how the last two stages act together here is the string after each of the first few and last stages:
~
~~
}~
}}~
|}~
||}~
{|}~
...
"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
Since the state of the string is only checked after every other stage to determine whether to end the loop, and the two stages cancel each other once we reach the leading space (since Stage 2 adds a space and Stage 3 removes it), this terminates the loop and therefore the program.