如何使用 preg_replace 删除 X 和 Y 之间的内容?
用于删除引用和目录“uploads/”之间的任何内容的正则表达式是什么?
使用正则表达式生成器,我得到这个: (?<=\=")[^]+?(?=uploads/)
$block_data = preg_replace('/(?<=\=")[^]+?(?=uploads/)/g','',$block_data);
但似乎正在删除所有内容:(
What would the regular expression be for removing any content between a quote, and the directory "uploads/"?
Using a regexpression generator, I get this: (?<=\=")[^]+?(?=uploads/)
$block_data = preg_replace('/(?<=\=")[^]+?(?=uploads/)/g','',$block_data);
But seems to be removing everything :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该转义“uploads/”中的“/”,并且
g
不是有效的修饰符,加上[^]
无效,我猜您想要。
相反。这是您的正则表达式:
ideone 上的测试
You should escape the "/" in "uploads/" and
g
isn't a valid modifier, plus[^]
is invalid, I guess you wanted.
instead.Here is your regex :
The test on ideone
简单的解决方案是
进行更改:
/
g
修饰符,这在 PHP 中是不必要的这可行,只要我可以看出,将
first"middle/uploads/end"
减少为first"uploads/end"
。The simple solution would be
Changes made:
/
in the lookaheadg
modifier, which is unnecessary in PHPThis works, so far as I can tell, reducing
first"middle/uploads/end"
tofirst"uploads/end"
.