Php Regex返回单词和括号的内容

Php Regex返回单词和括号的内容,php,regex,preg-match,preg-match-all,Php,Regex,Preg Match,Preg Match All,我需要什么正则表达式模式来提取PHP中具有前面特定字符串的一对括号的内容 所以如果我有一份声明 @includelayout( 'cms.layout.nav-header' ) 我只需要直接前面有@includeDelayOut的括号的内容 所以我只想让它回来: 'cms.layout.nav-header' 我目前正在使用: preg_match('/(?<!\w)(?:\s*)@includelayout((?:\s*)?\(.*)/', $value, $matches

我需要什么正则表达式模式来提取PHP中具有前面特定字符串的一对括号的内容

所以如果我有一份声明

@includelayout( 'cms.layout.nav-header' )
我只需要直接前面有@includeDelayOut的括号的内容

所以我只想让它回来:

'cms.layout.nav-header'
我目前正在使用:

preg_match('/(?<!\w)(?:\s*)@includelayout((?:\s*)?\(.*)/', $value, $matches);
这让我

array (size=2)
    0 => string '@includelayout( 'output.layout.nav-header' )' (length=46)
    1 => string '( 'output.layout.nav-header' )' (length=30)
但是我不能让它不返回括号


谢谢

从索引1中获取匹配的组:

(?<=@includelayout\()([^)]*)

(?您可以尝试使用下面的正则表达式来匹配paranthesis中的内容,而无需在paranthesis中使用前导和以下空格

@includelayout\(\s*\K.*?(?=\s*\))

如果要匹配字符串
@includelayout
前面的
()
中包含的所有字符,则可以尝试以下方法

@includelayout\(\K[^)]*

你的PHP代码是

<?php
$mystring = "@includelayout( 'cms.layout.nav-header' )";
$regex = '~@includelayout\(\K[^)]*~';
if (preg_match($regex, $mystring, $m)) {
    $yourmatch = $m[0]; 
    echo $yourmatch;
    }
?> //=>  'cms.layout.nav-header' 

太棒了。谢谢:)
<?php
$mystring = "@includelayout( 'cms.layout.nav-header' )";
$regex = '~@includelayout\(\K[^)]*~';
if (preg_match($regex, $mystring, $m)) {
    $yourmatch = $m[0]; 
    echo $yourmatch;
    }
?> //=>  'cms.layout.nav-header'