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中运行,这太棒了。我正在尝试动态构建正则表达式来处理命名组等。谢谢你帮了大忙,我试着投了赞成票,但它不让我。