1

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.

4
  • 1
    Try "/.*?(?=Kompatybilny)/su" instead of ".*(?=Kompatybilny)" Commented Feb 4, 2020 at 7:41
  • @WiktorStribiżew Perfect! Works as expected. Could you tell me one more thing? How to make it to show part of variable between 2 words? Commented Feb 4, 2020 at 7:47
  • 1
    Something like {$product.description|regex_replace:"/.*?Kompatybilny(.*?)Word2.*/su":'$1'}? Commented Feb 4, 2020 at 8:04
  • Super! Thank You very much! Commented Feb 4, 2020 at 8:23

1 Answer 1

1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.