preg_replace 和多个 NOT
我想用“受保护的函数 _someMethod()”替换所有“私有函数 __someMethod()”。 但我确实想让魔法保持不变。 但替换不起作用。
$x = array(
'/\bprivate function __([^(construct|destruct|sleep|wakeup|get|set|call|toString|invoke|set_state|clone|callStatic|isset|unset)])\b/i',
'protected function _\1'
)
\b
和 \b
作为字边界。
它使用 preg_replace($x[0], $x[1])
。
谢谢!
我还尝试了 [^construct^destruct^sleep]
等,
同样适用于 " $this->__ "
和 " ::__ "
(静态调用)然后,当然。
I want to replace all "private function __someMethod()" with "protected function _someMethod().
But I do want to leave the magic ones untouched.
The replacing does not work though.
$x = array(
'/\bprivate function __([^(construct|destruct|sleep|wakeup|get|set|call|toString|invoke|set_state|clone|callStatic|isset|unset)])\b/i',
'protected function _\1'
)
\b
and \b
as word boundaries.
it uses preg_replace($x[0], $x[1])
.
thx!
i also tried [^construct^destruct^sleep]
etc
the same applies to " $this->__ "
and " ::__ "
(static call) then, of course.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[^...]
语法是否定字符类。方括号中的所有内容都只是一个字符列表,()
和|
不会被解释,并且您的单词会被打乱成一个字母列表。您想要使用的是 否定断言
(?!....)
后面应该跟有
\w+
才能用于您的 preg_replacing。The
[^...]
syntax is a negated character class. Everything in square brackets is just a list of characters, the()
and the|
are not interpreted, and your words get shuffled into a list of letters.What you wanted to use was a negative assertion
(?!....)
It should be followed by
\w+
to work for your preg_replacing.