给定一些文本,我想删除所有介于{
和之间的文本}
。该块本身可能包含一些块。如何使用PCRE正则表达式来做到这一点?
\\example input:
{a}b{c{d}}e{f{g}h}
\\output:
be
使用正则表达式递归:
\{(?>[^{}]|(?R))*\}
PHP示例:
$input = '{a}b{c{d}}e{f{g}h}';
$output = preg_replace('/\{(?>[^{}]|(?R))*\}/', '', $input);
echo($output); # => be
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句