匹配顺序我有问题的正则表达式中PHP
The quick brown {fox} jumps over the lazy {dog}
我需要匹配包含在{}可发生在文本几次任何字符串以下示例文本。
我试着下面的代码,但它不能正常工作
<?php
$matches = array();
$string = "The quick brown {fox} jumps over the lazy {dog}";
preg_match("/\{(.*)\}/",$string,$matches);
print_r($matches);
?>
,这就是我得到
Array
(
[0] => {fox} jumps over the lazy {dog}
[1] => fox} jumps over the lazy {dog
)
我希望得到
Array
(
[0] => {fox} jumps over the lazy {dog}
[1] => fox
[2] => dog
)
所以,我怎么能强迫PHP匹配最近的“}”而不是匹配最后一个?
这很好。你能解释一下用法吗?在这种情况下 ?这种用法是否记录在案 – AssemblerGuy 2010-12-09 15:03:44