Php 带前向和后向的正则表达式

Php 带前向和后向的正则表达式,php,regex,match,Php,Regex,Match,我有下面的regexp,非常有效 $str = "ID: {{item:id}} & First name: {{item:first_name}} & Page Title: {{page:title}}"; preg_match_all('/(?<={{)[^}]*(?=}})/', $str, $matches); print_r($matches); Returns: Array ( [0] => Array (

我有下面的regexp,非常有效

$str = "ID: {{item:id}} & First name: {{item:first_name}} & Page Title: {{page:title}}";

preg_match_all('/(?<={{)[^}]*(?=}})/', $str, $matches);

print_r($matches);

Returns:
Array
(
    [0] => Array
        (
            [0] => item:id
            [1] => item:first_name
            [2] => page:title
        )
)
$str=“ID:{{item:ID}}&名字:{{{item:First{u name}}&页面标题:{{{Page:Title}}”;
preg_match_all('/(?您可以使用:

preg_match_all('/(?<={{)item:[^}]*(?=}})/', $str, $matches);

print_r($matches[0]);
Array
(
    [0] => item:id
    [1] => item:first_name
)

preg_match_all('/(?使用此选项,您可以对标记进行分组,因此不需要将表达式限制为任何单一类型:

(?<={{)(.+?)(?:\:)(.+?)(?=}})

我真的试过了(?非常好!谢谢。
$str = "ID: {{item:id}} & First name: {{item:first_name}} & Page Title: {{page:title}}";

preg_match_all('/(?<={{)(.+?)(?:\:)(.+?)(?=}})/', $str, $matches);

$tokens = array();

foreach ($matches[0] as $i => $v) {
    $tokens[$matches[1][$i]][] = $matches[2][$i];
}

echo '<pre>';
print_r($tokens);
Array
(
    [item] => Array
        (
            [0] => id
            [1] => first_name
        )

    [page] => Array
        (
            [0] => title
        )

)