Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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 Regex preg qoute模拟Regex_Php_Regex_Preg Replace - Fatal编程技术网

Php Regex preg qoute模拟Regex

Php Regex preg qoute模拟Regex,php,regex,preg-replace,Php,Regex,Preg Replace,我试图模仿preg_qoute的功能,而不转义字符,:() 到目前为止,我已经能够提出,[.\\+*?[^\]${}=!\124;],我将像下面那样使用它 preg_replace('#[.\\+*?[^\\]${}=!|]#', '\\\\$0', '(hello)/(goodbye/(<still there>))'); preg\u replace(“\\\\+*?[^\\]${}=!\\\]\\\\\$0',“\\\$0',”(你好)/(再见/())); 问题是它不是转义

我试图模仿
preg_qoute
的功能,而不转义字符,
:()

到目前为止,我已经能够提出,
[.\\+*?[^\]${}=!\124;]
,我将像下面那样使用它

preg_replace('#[.\\+*?[^\\]${}=!|]#', '\\\\$0', '(hello)/(goodbye/(<still there>))');
preg\u replace(“\\\\+*?[^\\]${}=!\\\]\\\\\$0',“\\\$0',”(你好)/(再见/()));
问题是它不是转义
/
字符,我得到了一个未转义的分隔符异常

有什么想法吗


谢谢。

我会这样写,在字符集中添加
/
-
。虽然我不清楚为什么你想模仿这个函数,而不去模仿其他角色

preg_replace('~[.+*?^$\\|[\]{}=!/-]~', '\\\\$0', '. \ + * ? [ ^ ] $ { } = ! | - ( ) < > :');
preg\u replace(“~[.+*?^$\\\\\\”[\]{}=!/-]~”、“\\\\$0”、“.\+*?[^]${}=!\124;-()<>:”);
输出

\. \ \+ \* \? \[ \^ \] \$ \{ \} \= \! \| \- ( ) < > :
\.\+\*\\[ \^ \] \$ \{ \} \= \! \| \- ( ) < > :

它没有转义
/
,因为它没有在字符集中定义。有什么帮助吗?我已经尝试过
\/
,但我无法让它在Ank you中运行,这太棒了。我正在尝试动态构建正则表达式来处理命名组等。谢谢你帮了大忙,我试着投了赞成票,但它不让我。