正则表达式抓取表单标签内容不起作用

发布于 2024-10-05 00:53:00 字数 153 浏览 12 评论 0原文

我正在尝试使用 preg_match_all 获取表单标签内的内容/标签,这是正则表达式

/<form\b[^>]*>(.*?)<\/form>/i

但我想知道,为什么它不起作用!有什么想法吗?

I am trying to grab contents/tags inside form tag using preg_match_all, here is the regular expression

/<form\b[^>]*>(.*?)<\/form>/i

But i wonder, why it doesn't work! Any idea?

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

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

发布评论

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

评论(2

乞讨 2024-10-12 00:53:00

默认情况下,. (DOT) 不匹配换行符。如果您使用 s 修饰符启用 DOT-ALL,它确实会匹配这些字符:

/<form\b[^>]*>(.*?)<\/form>/is

意识到您将无法匹配类似的内容:

<form>
   ...

   <!-- </form> -->

   ...
</form>

仅列出其中一种可能性。

By default, the . (DOT) does not match line breaks. If you enable DOT-ALL with the s modifier, it does match those chars:

/<form\b[^>]*>(.*?)<\/form>/is

Realize that you won't be able to match something like:

<form>
   ...

   <!-- </form> -->

   ...
</form>

to name just one of the possibilities.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文