regular expression in php: take the shortest match

前端 未结 5 1518
我寻月下人不归
我寻月下人不归 2021-01-12 05:23

I\'m trying to do a PHP regular expression but i can\'t find the right way ...

Imagine I have this string: \"hello, my {{name is Peter}} and {{I want to eat chocolat

5条回答
  •  有刺的猬
    2021-01-12 06:07

    EDITED

    As non-greedy matching seems to be faster than negated one (see here), I change my answer too. Thought it was the other way round...

    preg_match("/\{\{(.*?)\}\}/", $string)
    

    You might want to use preg_match_all to get all matches

提交回复
热议问题