我有一个演示 div 元素的 java 字符串:
String source = "<div class = \"ads\">\n" +
"\t<dl style = \"font-size:14px; color:blue;\">\n" +
"\t\t<li>\n" +
"\t\t\t<a href = \"http://ggicci.blog.163.com\" target = \"_blank\">Ggicci's Blog</a>\n" +
"\t\t</li>\n" +
"\t</dl>\n" +
"</div>\n";
html形式的内容是:
<div class = "ads">
<dl style = "font-size:14px; color:blue;">
<li>
<a href = "http://ggicci.blog.163.com" target = "_blank">Ggicci's Blog</a>
</li>
</dl>
</div>
我写了这样一个正则表达式来提取 dl 元素:
<dl[.\\s]*?>[.\\s]*?</div>
但它什么也没找到,我将其修改为:
<dl(.|\\s)*?>(.|\\s)*?</div>
然后它工作。所以我这样测试:
System.out.println(Pattern.matches("[.\\s]", "a")); --> false
System.out.println(Pattern.matches("[abc\\s]", "a")); --> true
那为什么是'。不能匹配'a'?