preg_match_all() [function.preg-match-all]: 未知修饰符 ']'

发布于 2024-07-10 17:08:41 字数 184 浏览 4 评论 0原文

使用了几种不同的模式,但它们都出现了这个错误 - 那么出了什么问题呢?

我最短的诊断是:

$pattern = "<img([^>]*[^/])>";
preg_match_all($pattern, $subject, $matches);

谢谢

Using a few different patterns but they each come up with this error - so what's wrong?

My shortest one to diagnose is:

$pattern = "<img([^>]*[^/])>";
preg_match_all($pattern, $subject, $matches);

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

画离情绘悲伤 2024-07-17 17:08:41

您缺少正则表达式分隔符。 尝试:

$pattern = "#<img([^>]*[^/])>#i";

You are lacking the regexp delimiters. Try:

$pattern = "#<img([^>]*[^/])>#i";
余罪 2024-07-17 17:08:41

单斜杠是默认分隔符,这就是为什么原始正则表达式中它后面的字符出现在错误消息中的原因。
使用传统的斜杠作为分隔符并转义不是分隔符的斜杠,如下所示:

$pattern = "/<img([^>]*[^\\/])>/";

A single slash is the default delimiter, which is why the character after it in your original regex was in the error-message.
Using the traditional slashes as delimiters and escaping the slash that is not a delimiter would look like this:

$pattern = "/<img([^>]*[^\\/])>/";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文