Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中,如何替换preg_中的一两个正则表达式?_Php_Regex - Fatal编程技术网

在PHP中,如何替换preg_中的一两个正则表达式?

在PHP中,如何替换preg_中的一两个正则表达式?,php,regex,Php,Regex,我想知道在PHP中,我可以在preg_replace中合并下面两个正则表达式吗?如果是的话,请向我解释一下你是如何做到的 // I want to make it one line code $plaintext = preg_replace('/\(.*?\)/u', "", $plaintext); $plaintext = preg_replace("/\([^)]+\)/u", "", $plaintext); //Output like $pl

我想知道在PHP中,我可以在preg_replace中合并下面两个正则表达式吗?如果是的话,请向我解释一下你是如何做到的

// I want to make it one line code
$plaintext = preg_replace('/\(.*?\)/u', "", $plaintext);
$plaintext = preg_replace("/\([^)]+\)/u", "", $plaintext);

//Output like 
 $plaintext = preg_replace('/\(.*?\)/u' | "/\([^)]+\)/u", "", $plaintext);
像这样的

$plaintext = preg_replace("/(\(.*?\))|(\([^)]+\))/u", "", $plaintext);

嗯,简单地把管道符号放在正则表达式之间?你可以使用preg\u replace\u回调函数来实现这一点。你用
试过了吗:
preg\u replace('/\&&&x28;*?\&&&&([^]+\)/u',“,$plaintext)
@Justinas Yahh,但不起作用。请提供
$plaintext
的输入和输出示例