提取括号中未包含的文本


Extract text not included in a parenthesis

选择括号内的字符串,

$text = 'ignore everything except this (text)';
preg_match('#'((.*?)')#', $text, $match);

echo $match[1] . ' /parentheses';

如何回显不在括号内的文本?

尝试如下:

$text = 'ignore everything except this (text)';
preg_match('/(.*)'((.*?)')/', $text, $match);
echo "in parenthesis: " . $match[2] . "'n";
echo "outside parenthesis: " . $match[1] . "'n";

不用说,它假设了一组括号

尝试:

preg_match('^(*.?)'((*.?)')(*.?)$', $text, $match);
echo $match[0] . $match[2];

假设只有一组括号