在 smarty 中数 preg_match

Counting preg_match in smarty

如何在 smarty 中计算 preg_match 匹配项?为什么以下内容不起作用?

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

{$match|@count}

据我了解您的需求,以下确实有效,只是让正则表达式不贪心:

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