<?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]); }
You have javascript disabled. You will not be able to edit any code.