regular expression in php: take the shortest match

前端 未结 5 1555
我寻月下人不归
我寻月下人不归 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 05:50

    Use

    "/{{(.*?)}}/"
    

    The expression ".*" is greedy, taking as many characters as possible. If you use ".*?" is takes as little characters as possible, that is it stops at the first set of closing brackets.

提交回复
热议问题