正则表达式来抓取表单标签内容不起作用 [英] Regular expression to grab form tag content doesn't work
本文介绍了正则表达式来抓取表单标签内容不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用preg_match_all抓取表单标签中的内容/标签,这里是正则表达式
/< form \ b [^>] *>(。*?)< \ form \\ gt; / i
但我想知道,为什么它不起作用!任何想法?
解决方案
默认情况下,。
不符合换行符。如果您使用 s
修饰符启用DOT-ALL,则它与这些字符匹配:
/< form \b [^>] *>(。*?)< \ / form> /是
意识到您无法匹配以下内容:
< ;形式>
...
<! - < / form> - >
...
< / form>
仅仅是其中一种可能性。
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?
解决方案
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.
这篇关于正则表达式来抓取表单标签内容不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文