我试图用preg_match_all获得所有{{product.smth}},但是如果我在一行中没有这样的内容,我会得到错误的结果。preg_match_all问题
例子:
$smth = '<name>{{product.name}}</name><getname>{{product.getName()}}</getname>';
$pattern = '/\{\{product\.(.*)\}\}/';
preg_match_all($pattern, $smth, $matches);
//returns '{{product.name}}</name><getname>{{product.getName()}}'
//instad of '{{product.name}}' and '{{product.getName()}}'
什么IAM做错了什么?请帮忙。
使用'/ U'修饰符。 –
@Ωmega我更喜欢修饰符:)注意,ungreedy只是与它切换,所以'/.*?/ U'就是贪婪的例子。 –