Search code examples
regexsmartyprestashop-1.6

Problem with regex_replace in prestashop smarty


I'm trying to use regex_replace in prestashop product_list.tpl. My code is like:

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

I'd like it to show $product.destription after "Kompatybilny" word, but it doesn't work and I don't know why. I've tried different regex functions but still the same - variable doesn't show at all.


Solution

  • You may use

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

    The regex will match

    • .*? - any 0+ chars, as few as possible, up to (but excluding from the match) the first occurrence of
    • (?=Kompatybilny) - the Kompatybilny substring
    • su - s means . can match linebreak chars and u supports Unicode strings.