3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = 'foo [abc - def - ghi - jkl] bar'; $regex = <<<REGEX / (?: #start a non-capturing group \[ #match a left square brace (?=[a-z -]+]) #lookahead for the completion of a valid placeholder expression | #or \G(?!^) #continue from end position of last match and not the start of the string \s-\s #match a whitespace, hyphen then a whitespace ) #close the non-capturing group \K #forget any matched characters up to this position [a-z]+ #match one or more lowercase ascii letters /x REGEX; if (preg_match_all($regex, $text, $match)) { var_export($match[0]); }
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.14
array ( 0 => 'abc', 1 => 'def', 2 => 'ghi', 3 => 'jkl', )

preferences:
68.64 ms | 406 KiB | 5 Q