prestashop smarty 中 regex_replace 的问题

Problem with regex_replace in prestashop smarty

我正在尝试在 prestashop product_list.tpl 中使用 regex_replace。我的代码是这样的:

{$product.description|regex_replace:".*(?=Kompatybilny)":""|strip_tags:'UTF-8'}

我希望它在 "Kompatybilny" 字词后显示 $product.destription,但它不起作用,我也不知道为什么。我尝试了不同的正则表达式函数,但仍然相同 - 变量根本不显示。

您可以使用

{$product.description|regex_replace:"/.*?(?=Kompatybilny)/su":''}

正则表达式将匹配

  • .*? - 任何 0+ 个字符,尽可能少,直到(但不包括在匹配中)第一次出现
  • (?=Kompatybilny) - Kompatybilny 子串
  • su - s 表示 . 可以匹配换行字符,u 支持 Unicode 字符串。