3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $re = "@ ^([\\x20\\t]*)/\\*!\\* (?:[\\x20\\t]*(!?\\w*))? # Start with some indent, a comment with the special marker, then an optional name ((?:[^*]|\\*[^/])*) # Any amount of \"a character that isnt a star, or a star not followed by a / \\*/ # The comment end @mx"; $str = "use hafriedlander\Peg\Parser;\n\nclass FQL extends Parser\Basic\n{\n /*!* FQL\n Quote: !'\\''\"'\n Character: /[^\t\n\r\"]/\n Word: w:('\\\"' | Character)+\n function w(&\$res, \$sub) {\n if ( !isset(\$res['val']) ) \$res['val'] = '';\n \$res['val'] .= \$sub['text'];\n }\n FunctionName: w:/ \w+ /\n function w(&\$res, \$sub) {\n if ( !isset(\$res['val']) ) \$res['val'] = '';\n \$res['val'] .= \$sub['text'];\n }\n Connector: c:/ ((a|A)(n|N)(d|D))|((x|X)(o|O)(r|R))|((o|O)(r|R)) /\n function c(&\$res, \$sub) {\n \$res['val'] = strtolower(\$sub['text']);\n }\n Operand: o:/ !((h|H)(a|A)(s|S))|((h|H)(a|A)(s|S))|!((i|I)(n|N))|((i|I)(n|N))|!=|>=|<=|=|<|> /\n function o(&\$res, \$sub) {\n \$res['val'] = strtolower(\$sub['text']);\n }\n ValueAtom: > (Quote atom:Word Quote | emptyAtom:'\"\"') >\n function atom(&\$res, \$sub) {\n \$res['val'] = \$sub['val'];\n }\n function emptyAtom(&\$res, \$sub) {\n \$res['val'] = \"\";\n }\n ValueList: > '[' > atom:ValueAtom (> ',' > rest:ValueAtom)* > ']' >\n function atom(&\$res, \$sub) {\n \$res['val'] = [\$sub['val']];\n }\n function rest(&\$res, \$sub) {\n \$res['val'][] = \$sub['val'];\n }\n ControlAtom: > Quote '#' atom:Word Quote >\n function atom(&\$res, \$sub) {\n \$res['val'] = \$sub['val'];\n }\n ColumnAtom: > Quote > ':' atom:Word Quote >\n function atom(&\$res, \$sub) {\n \$res['val'] = \$sub['val'];\n }\n FunctionAtom: > fnc:FunctionName > '(' atom:ControlAtom (',' > params:ValueAtom >)* ')' >\n function atom(&\$res, \$sub) {\n \$res['val'] = \$sub['val'];\n }\n function fnc(&\$res, \$sub) {\n \$res['fnc'] = strtolower(\$sub['val']);\n \$res['params'] = [];\n }\n function params(&\$res, \$sub) {\n \$res['params'][] = \$sub['val'];\n }\n Assignment: (control:FunctionAtom | control:ControlAtom | control:ColumnAtom) operand:Operand (value:ValueList | value:ValueAtom)\n Block: > ('(' > block:Statement+ > ')') | block:Assignment\n Statement: (left:Block > connector:Connector > right:Statement) | (left:Block > !Connector)\n */\n}"; preg_match($re, $str, $matches); var_dump($matches);
based on v0DYI
Output for 5.3.20 - 5.6.28, 7.0.6 - 7.2.0
array(4) { [0]=> string(2091) " /*!* FQL Quote: !'\''"' Character: /[^ "]/ Word: w:('\"' | Character)+ function w(&$res, $sub) { if ( !isset($res['val']) ) $res['val'] = ''; $res['val'] .= $sub['text']; } FunctionName: w:/ \w+ / function w(&$res, $sub) { if ( !isset($res['val']) ) $res['val'] = ''; $res['val'] .= $sub['text']; } Connector: c:/ ((a|A)(n|N)(d|D))|((x|X)(o|O)(r|R))|((o|O)(r|R)) / function c(&$res, $sub) { $res['val'] = strtolower($sub['text']); } Operand: o:/ !((h|H)(a|A)(s|S))|((h|H)(a|A)(s|S))|!((i|I)(n|N))|((i|I)(n|N))|!=|>=|<=|=|<|> / function o(&$res, $sub) { $res['val'] = strtolower($sub['text']); } ValueAtom: > (Quote atom:Word Quote | emptyAtom:'""') > function atom(&$res, $sub) { $res['val'] = $sub['val']; } function emptyAtom(&$res, $sub) { $res['val'] = ""; } ValueList: > '[' > atom:ValueAtom (> ',' > rest:ValueAtom)* > ']' > function atom(&$res, $sub) { $res['val'] = [$sub['val']]; } function rest(&$res, $sub) { $res['val'][] = $sub['val']; } ControlAtom: > Quote '#' atom:Word Quote > function atom(&$res, $sub) { $res['val'] = $sub['val']; } ColumnAtom: > Quote > ':' atom:Word Quote > function atom(&$res, $sub) { $res['val'] = $sub['val']; } FunctionAtom: > fnc:FunctionName > '(' atom:ControlAtom (',' > params:ValueAtom >)* ')' > function atom(&$res, $sub) { $res['val'] = $sub['val']; } function fnc(&$res, $sub) { $res['fnc'] = strtolower($sub['val']); $res['params'] = []; } function params(&$res, $sub) { $res['params'][] = $sub['val']; } Assignment: (control:FunctionAtom | control:ControlAtom | control:ColumnAtom) operand:Operand (value:ValueList | value:ValueAtom) Block: > ('(' > block:Statement+ > ')') | block:Assignment Statement: (left:Block > connector:Connector > right:Statement) | (left:Block > !Connector) */" [1]=> string(4) " " [2]=> string(3) "FQL" [3]=> string(2077) " Quote: !'\''"' Character: /[^ "]/ Word: w:('\"' | Character)+ function w(&$res, $sub) { if ( !isset($res['val']) ) $res['val'] = ''; $res['val'] .= $sub['text']; } FunctionName: w:/ \w+ / function w(&$res, $sub) { if ( !isset($res['val']) ) $res['val'] = ''; $res['val'] .= $sub['text']; } Connector: c:/ ((a|A)(n|N)(d|D))|((x|X)(o|O)(r|R))|((o|O)(r|R)) / function c(&$res, $sub) { $res['val'] = strtolower($sub['text']); } Operand: o:/ !((h|H)(a|A)(s|S))|((h|H)(a|A)(s|S))|!((i|I)(n|N))|((i|I)(n|N))|!=|>=|<=|=|<|> / function o(&$res, $sub) { $res['val'] = strtolower($sub['text']); } ValueAtom: > (Quote atom:Word Quote | emptyAtom:'""') > function atom(&$res, $sub) { $res['val'] = $sub['val']; } function emptyAtom(&$res, $sub) { $res['val'] = ""; } ValueList: > '[' > atom:ValueAtom (> ',' > rest:ValueAtom)* > ']' > function atom(&$res, $sub) { $res['val'] = [$sub['val']]; } function rest(&$res, $sub) { $res['val'][] = $sub['val']; } ControlAtom: > Quote '#' atom:Word Quote > function atom(&$res, $sub) { $res['val'] = $sub['val']; } ColumnAtom: > Quote > ':' atom:Word Quote > function atom(&$res, $sub) { $res['val'] = $sub['val']; } FunctionAtom: > fnc:FunctionName > '(' atom:ControlAtom (',' > params:ValueAtom >)* ')' > function atom(&$res, $sub) { $res['val'] = $sub['val']; } function fnc(&$res, $sub) { $res['fnc'] = strtolower($sub['val']); $res['params'] = []; } function params(&$res, $sub) { $res['params'][] = $sub['val']; } Assignment: (control:FunctionAtom | control:ControlAtom | control:ColumnAtom) operand:Operand (value:ValueList | value:ValueAtom) Block: > ('(' > block:Statement+ > ')') | block:Assignment Statement: (left:Block > connector:Connector > right:Statement) | (left:Block > !Connector) " }
Output for 7.0.0 - 7.0.5
array(0) { }