且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

php中的正则表达式:取最短匹配

更新时间:2022-05-20 22:38:50

使用

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

表达式 ".*" 是贪婪的,取尽可能多的字符.如果您使用 ".*?" 则需要尽可能少的字符,即它停在第一组右括号处.

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.