我试图模仿preg_qoute的功能,而不转义字符,: ( ) < >。
到目前为止,我已经想出了,[.\\+*?[^\\]${}=!|]和我会像下面这样使用它
preg_replace('#[.\\+*?[^\\]${}=!|]#', '\\\\$0', '(hello)/(goodbye/(<still there>))');问题是不是,而是转义/字符,我得到了一个未转义的分隔符异常。
有什么想法吗?
谢谢。
发布于 2014-09-05 22:00:03
我会这样写出来,将/和-添加到字符集中。虽然我不清楚为什么要模仿这个函数而不让其他字符转义。
preg_replace('~[.+*?^$\\|[\]{}=!/-]~', '\\\\$0', '. \ + * ? [ ^ ] $ { } = ! | - ( ) < > :');输出
\. \ \+ \* \? \[ \^ \] \$ \{ \} \= \! \| \- ( ) < > :https://stackoverflow.com/questions/25694338
复制相似问题