3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // // () [] {} <> // // when not using them in the expression itself echo '(123) ', preg_match('(123)', "123"), "\n"; // when using them balanced echo '[[123]] ', preg_match('[[123]]', "1"), "\n"; // when using them unbalanced: <> which is rarely special echo '<1 < 2> ', preg_match('<1 < 2>', "1 < 2"), "\n"; // warning // must be escaped echo '<1 \< 2> ', preg_match('<1 \< 2>', "1 < 2"), "\n\n"; // when using them unbalanced: {} which is almost always special echo '{function [({]} ', preg_match('{function [({]}', "function () {"), "\n"; // warning // must be escaped even when it represents a literal character echo '{function [(\{]} ', preg_match('{function [(\{]}', "function () {"), "\n\n"; // // other plain symbols // echo '!1! ', preg_match('!1!', "1"), "\n"; echo '%1% ', preg_match('%1%', "1"), "\n"; echo '_1_ ', preg_match('_1_', "1"), "\n"; // // other symbols that can be special: # $ ^ * + | . ? // these will break your expression // echo '^^123$^ ', preg_match('^^123$^', "123"), "\n"; // warning echo '^\^123$^ ', preg_match('^\^123$^', "123"), "\n\n"; // no match (would match '^123' at the end of the string) echo '|(foo|bar|baz)| ', preg_match('|(foo|bar|baz)|', "foo"), "\n"; // warning echo '|(foo\|bar\|baz)| ', preg_match('|(foo\|bar\|baz)|', "foo"), "\n\n"; // no match (would match 'foo|bar|baz') // // beware: even - ' can be special // // - for a character set range echo '-[a-zA-Z]- ', preg_match('-[a-zA-Z]-', "m"), "\n"; // warning echo '-[a\-zA\-Z]- ', preg_match('-[a\-zA\-Z]-', "m"), "\n\n"; // no match (would match 'a' '-' 'z' 'A' 'Z') // ' for named subpatterns echo "'(?'alpha'[a-zA-Z])\k'alpha'' ", preg_match("'(?'alpha'[a-zA-Z])\k'alpha''", "mm"), "\n"; // warning about delimiter echo "'(?\'alpha\'[a-zA-Z])\k\'alpha\'' ", preg_match("'(?\'alpha\'[a-zA-Z])\k\'alpha\''", "mm"), "\n\n"; // warning about syntax
Output for 4.4.9, 5.2.6 - 7.1.0
(123) 1 [[123]] 1 <1 < 2> Warning: preg_match(): No ending matching delimiter '>' found in /in/7IgoG on line 14 <1 \< 2> 1 {function [({]} Warning: preg_match(): No ending matching delimiter '}' found in /in/7IgoG on line 19 {function [(\{]} 1 !1! 1 %1% 1 _1_ 1 ^^123$^ Warning: preg_match(): Unknown modifier '1' in /in/7IgoG on line 36 ^\^123$^ 0 |(foo|bar|baz)| Warning: preg_match(): Unknown modifier 'b' in /in/7IgoG on line 39 |(foo\|bar\|baz)| 0 -[a-zA-Z]- Warning: preg_match(): Unknown modifier 'z' in /in/7IgoG on line 47 -[a\-zA\-Z]- 0 '(?'alpha'[a-zA-Z])\k'alpha'' Warning: preg_match(): Unknown modifier 'a' in /in/7IgoG on line 51 '(?\'alpha\'[a-zA-Z])\k\'alpha\'' Warning: preg_match(): Compilation failed: unrecognized character after (? or (?- at offset 2 in /in/7IgoG on line 52
Output for 4.3.11 - 4.4.8, 5.0.0 - 5.0.5, 5.1.1 - 5.2.5
(123) 1 [[123]] 1 <1 < 2> Warning: preg_match(): No ending matching delimiter '>' found in /in/7IgoG on line 14 <1 \< 2> 1 {function [({]} Warning: preg_match(): No ending matching delimiter '}' found in /in/7IgoG on line 19 {function [(\{]} 1 !1! 1 %1% 1 _1_ 1 ^^123$^ Warning: preg_match(): Unknown modifier '1' in /in/7IgoG on line 36 ^\^123$^ 0 |(foo|bar|baz)| Warning: preg_match(): Unknown modifier 'b' in /in/7IgoG on line 39 |(foo\|bar\|baz)| 0 -[a-zA-Z]- Warning: preg_match(): Unknown modifier 'z' in /in/7IgoG on line 47 -[a\-zA\-Z]- 0 '(?'alpha'[a-zA-Z])\k'alpha'' Warning: preg_match(): Unknown modifier 'a' in /in/7IgoG on line 51 '(?\'alpha\'[a-zA-Z])\k\'alpha\'' Warning: preg_match(): Compilation failed: unrecognized character after (? at offset 2 in /in/7IgoG on line 52
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/7IgoG on line 52
Process exited with code 255.
Output for 4.3.0 - 4.3.10
(123) 1 [[123]] 1 <1 < 2> Warning: No ending matching delimiter '>' found in /in/7IgoG on line 14 <1 \< 2> 1 {function [({]} Warning: No ending matching delimiter '}' found in /in/7IgoG on line 19 {function [(\{]} 1 !1! 1 %1% 1 _1_ 1 ^^123$^ Warning: Unknown modifier '1' in /in/7IgoG on line 36 ^\^123$^ 0 |(foo|bar|baz)| Warning: Unknown modifier 'b' in /in/7IgoG on line 39 |(foo\|bar\|baz)| 0 -[a-zA-Z]- Warning: Unknown modifier 'z' in /in/7IgoG on line 47 -[a\-zA\-Z]- 0 '(?'alpha'[a-zA-Z])\k'alpha'' Warning: Unknown modifier 'a' in /in/7IgoG on line 51 '(?\'alpha\'[a-zA-Z])\k\'alpha\'' Warning: Compilation failed: unrecognized character after (? at offset 2 in /in/7IgoG on line 52