Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
/
(?P<rulename><\S+>)\s*::=\s*(?P<production>(?:(?=\#)\#[^\r\n]*|(?!<\S+>\s*::=).+?)+)
/
gs
Input 1
1
# ***************************************************************************** # Smallest grammar # ***************************************************************************** # structure <predefined> ::= 'b0 = b1 = b2 = bool()' 'i0 = i1 = i2 = int()' 'res = int()' <code> # ***************************************************************************** <bool_var> ::= 'b0' | 'b1' | 'b2' <int_var> ::= 'i0' | 'i1' | 'i2' | 'in0' | 'in1' | 'in2' | 'in3' | 'res' # ***************************************************************************** <code> ::= <code><code> | <statement>'\n' <statement> ::= <assign> | <compound_stmt> <compound_stmt> ::= <if> | <while> # from bool <assign> ::= <bool_assign> # from int | <int_assign> <if> ::= <if-then> | <if-then><else> <if-then> ::= 'if '<bool><block> <else> ::= 'else'<block> <block> ::= ':{:\n'<code>':}' <while> ::= <loop-header>'while '<bool><loop-block> <loop-header> ::= 'loopBreak% = 0\n' # stop[0] is set by outer code to break immediately <loop-block> ::=':{:\n'<code>'\nif loopBreak% > loopBreakConst or stop[0]:{:\nbreak\n:}\nloopBreak% += 1:}' # bool <bool_assign> ::= <bool_var>' = '<bool> <bool_var_const> ::= <bool_var> | <bool_const> <bool> ::= <bool_var> | <bool_const> | <bool_pre> <bool_var_const> | '(' <bool_var_const> <bool_op> <bool_var_const> ')' # from int | <int> <comp_op> <int> <bool_op> ::= 'and' | 'or' <bool_pre> ::= 'not' <bool_const> ::= 'True' | 'False' # int <int_assign> ::= <int_var> '=' <int> | <int_var> <arith_assign> <int> <int_var_const> ::= <int_var> | <int_const> <int> ::= <int_var> | <int_const> | <arith_prefix><int_var_const> | '(' <int_var_const> <arith_ops> <int_var_const> ')' | <int_arith_ops_protected>'('<int_var_const>','<int_var_const>')' | 'min('<int_var_const>', '<int_var_const>')' | 'max('<int_var_const>', '<int_var_const>')' | 'abs('<int_var_const>')' # to avoid problems with leading zeros in python int <int_const> ::= 'int('<number>'.0)' <number> ::= <num> | <num><num> | <num><num><num> | <num><num><num><num> | <num><num><num><num><num> | <num><num><num><num><num><num> | <num><num><num><num><num><num><num> | <num><num><num><num><num><num><num><num> | <num><num><num><num><num><num><num><num><num> | <num><num><num><num><num><num><num><num><num><num> <num> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 <arith_assign> ::= <arith_ops>'=' <arith_ops> ::= '+'|'-'|'*' # ** raises ZeroDivision error when 'a = 0; a ** ~a' # |'**' <int_arith_ops_protected> ::= 'divInt' | 'mod' <arith_prefix> ::= '+'|'-' #|'~' <comp_op> ::= '<'|'>'|'=='|'>='|'<='|'!='|'is'|'is not'
Substitution
# ***************************************************************************** # Smallest grammar # ***************************************************************************** # structure <predefined> ::= 'b0 = b1 = b2 = bool()' 'i0 = i1 = i2 = int()' 'res = int()' <code> # ***************************************************************************** <bool_var> ::= 'b0' | 'b1' | 'b2' <int_var> ::= 'i0' | 'i1' | 'i2' | 'in0' | 'in1' | 'in2' | 'in3' | 'res' # ***************************************************************************** <code> ::= <code><code> | <statement>'\n' <statement> ::= <assign> | <compound_stmt> <compound_stmt> ::= <if> | <while> # from bool <assign> ::= <bool_assign> # from int | <int_assign> <if> ::= <if-then> | <if-then><else> <if-then> ::= 'if '<bool><block> <else> ::= 'else'<block> <block> ::= ':{:\n'<code>':}' <while> ::= <loop-header>'while '<bool><loop-block> <loop-header> ::= 'loopBreak% = 0\n' # stop[0] is set by outer code to break immediately <loop-block> ::=':{:\n'<code>'\nif loopBreak% > loopBreakConst or stop[0]:{:\nbreak\n:}\nloopBreak% += 1:}' # bool <bool_assign> ::= <bool_var>' = '<bool> <bool_var_const> ::= <bool_var> | <bool_const> <bool> ::= <bool_var> | <bool_const> | <bool_pre> <bool_var_const> | '(' <bool_var_const> <bool_op> <bool_var_const> ')' # from int | <int> <comp_op> <int> <bool_op> ::= 'and' | 'or' <bool_pre> ::= 'not' <bool_const> ::= 'True' | 'False' # int <int_assign> ::= <int_var> '=' <int> | <int_var> <arith_assign> <int> <int_var_const> ::= <int_var> | <int_const> <int> ::= <int_var> | <int_const> | <arith_prefix><int_var_const> | '(' <int_var_const> <arith_ops> <int_var_const> ')' | <int_arith_ops_protected>'('<int_var_const>','<int_var_const>')' | 'min('<int_var_const>', '<int_var_const>')' | 'max('<int_var_const>', '<int_var_const>')' | 'abs('<int_var_const>')' # to avoid problems with leading zeros in python int <int_const> ::= 'int('<number>'.0)' <number> ::= <num> | <num><num> | <num><num><num> | <num><num><num><num> | <num><num><num><num><num> | <num><num><num><num><num><num> | <num><num><num><num><num><num><num> | <num><num><num><num><num><num><num><num> | <num><num><num><num><num><num><num><num><num> | <num><num><num><num><num><num><num><num><num><num> <num> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 <arith_assign> ::= <arith_ops>'=' <arith_ops> ::= '+'|'-'|'*' # ** raises ZeroDivision error when 'a = 0; a ** ~a' # |'**' <int_arith_ops_protected> ::= 'divInt' | 'mod' <arith_prefix> ::= '+'|'-' #|'~' <comp_op> ::= '<'|'>'|'=='|'>='|'<='|'!='|'is'|'is not'