Search code examples
preg-matchsmarty

Counting preg_match in smarty


How to count preg_match matches in smarty? Why is the following not working?

{preg_match("/\[PGN.*](.*)\[\/PGN.*\]/", $code, $match)}

{$match|@count}

Solution

  • As far as I understand your needs, the following does work, just make the regex not greedy:

    preg_match_all("~\[PGN\d+](.+?)\[/PGN\d+]~", $code, $match)