Compile Regexes (By Substitution) Your task is to compile regexes... by specifying a substitution for each character in a regex.

Regexes

The regexes support these

REGEX       = (LITERAL REGEX / GROUP REGEX / STAR REGEX / ALTERNATIVE)
LITERAL     = 1 / 0
GROUP       = '(' REGEX ')'
STAR        = (LITERAL / GROUP) '*'
ALTERNATIVE = '('REGEX ('|' REGEX)*')'


Why only 1 or 0? It is for simplification. The regex thus has only the following characters:

*()|10


It is interpreted as follows:


* is Kleene star (repeat left group or literal 0 or more times).
| is alternation (match if either the regex to the left or the regex to the right matches).
() is grouping.
1 matches character 1.
0 matches character 0.


How to compile?

You specify six code snippets: one to replace each regex character. For example, if your answer is:


  * : FSAGFSDVADFS 
  | : GSDGSAG 
  ( : GSDG 
  ) : GDSIH 
  1 : RGIHAIGH 
  0 : GIHEBN


Then you replace each regex with its respective code snippet, so:

(0|11)*


is turned into:

GSDGGIHEBNGSDGSAGRGIHAIGHRGIHAIGHGDSIHFSAGFSDVADFS


What is the resulting program supposed to do?

Your program will:


Take the input.
Output a truthy value if the regex matches whole input.
Else output a falsy value.


Input outside 01 is consindered undefined behavior. Input can be empty.

Additional rules


For a given regex character, the resulting snippet must always be the same.
There is no prefix or suffix character added afterwards.
The regex is guaranteed to be nonempty.


Scoring

The least combined snippet is the winner. So the score for the example case would be calculated as follows:

FSAGFSDVADFS + GSDGSAG + GSDG + GDSIH + RGIHAIGH + GIHEBN

12 + 7 + 4 + 5 + 8 + 6 = 42
Snails, 48 bytes
0 -&gt; )0(\0!(l.)(~
1 -&gt; )0(\1!(l.)(~
( -&gt; )0({{(
) -&gt; )0}}(~
| -&gt; )0}|{(
* -&gt; )0),(~
If we had to search for partial matches rather than matching only the full input, then it would be very easy. 0 would become \0, 1 would become \1, * would become ,, and the others would map to themselves. Instead there are a lot of shenanigans to prevent matches from starting somewhere other than the beginning or ending somewhere other than the end. !(l.) is an assertion that will fail if the beginning of the match is not at the beginning of the input. ~ matches a cell outside of the input, so it is added to all the characters that are allowed to be at the end of the regex. If there is another regex character following, it is canceled out by a numerical quantifier 0 which requires it to be matched 0 times, essentially commenting it out. To allow * (,) to work correctly despite the dummy out-of-bounds test being in the way, the language's bracket matching rules are heavily used. From the documentation:

Matching pairs of parentheses () or curly braces {} will behave as expected (like parentheses in regex), but it is also possible to leave out one half of a pair and have it inferred, according to the following rules. ) or } groups everything to the left until the nearest unclosed group opening instruction of the same type(( or { respectively), or the beginning of the pattern if none exists. It closes any unclosed opening instructions of the opposite type in the middle of this range. An otherwise unmatched ( or { is closed by the end of the pattern.

Clear as mud, right?