preg_match for information in parentheses(括号中的PRIG_MATCH信息)
问题描述
(ACCTG)会计 上面的文本,我试图获得括号中的信息,我应该如何在php中做到这一点,这就是我到目前为止所掌握的。
$regex = '#((([^()]+|(?R))*))#';
if (preg_match_all($regex, $string ,$matches)) {
echo implode(' ', $matches[1]);
} else {
//no parenthesis
echo $string;
}
推荐答案
为了便于在正则表达式中使用,我将特殊字符转换为十六进制
<?
$input = 'abc ("an example")';
if(preg_match("/x28([^x29]+)x29/", $input, $matched)) {
//...
print_r($matched);
} else {
//do something..
}
?>
这篇关于括号中的PRIG_MATCH信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!