[英]PHP pcre regex to find content of curly brackets
I need PHP pcre regex to find content of all curly brackets... Why is this regex doesn't work? 我需要PHP pcre正则表达式来查找所有大括号的内容...为什么此正则表达式不起作用?
<?php
$str = "test{it}test{/it}test";
$ret = preg_match_all("#\{.?\}#u", $str, $matches);
print_r($matches);
?>
I expect $matches
to contain {it}
and {/it}
- but it's empty.... 我希望
$matches
包含{it}
和{/it}
-但它是空的。
I think this is the version you are looking for: {.*?}
with the *
before the ?
我认为这是您要查找的版本:
{.*?}
在?
之前带有*
$re = "/{.*?}/";
$str = "test{it}test{/it}test";
preg_match_all($re, $str, $matches);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.