关于一个正则表示的错误

gnefgnehz 2011-07-14 09:13:52
我有一段HTML源码,现在我想提取其中位于<pre>和</pre>标签之间的内容,不过始终提取不到。HTML代码如下:
<html><head><title>Compile Error</title></head><body>
<ul><li><font color=#333399 size=5>Compile Error</font></li><p><font size=3>
<pre>F:\temp\8888092.1469\Main.java:1: illegal character: \35
#include<stdio.h>
^
F:\temp\8888092.1469\Main.java:5: class, interface, or enum expected
__int64 n,k;
^
F:\temp\8888092.1469\Main.java:6: class, interface, or enum expected
scanf("%d",&t);
^
F:\temp\8888092.1469\Main.java:7: class, interface, or enum expected
while(t--)
^
F:\temp\8888092.1469\Main.java:10: class, interface, or enum expected
k=n*n;
^
F:\temp\8888092.1469\Main.java:11: class, interface, or enum expected
if(k>10000)
^
F:\temp\8888092.1469\Main.java:13: class, interface, or enum expected
else
^
F:\temp\8888092.1469\Main.java:15: class, interface, or enum expected
}
^
F:\temp\8888092.1469\Main.java:17: class, interface, or enum expected
}
^
9 errors
</pre>
</font></p></ul></body></html>



我的正则表达式如下:
<pre>(.*?)<\/pre>


请高手指点,小弟不胜感激!!!
...全文
70 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
noevil 2011-07-15
  • 打赏
  • 举报
回复
. 是不匹配换行符的
gnefgnehz 2011-07-15
  • 打赏
  • 举报
回复
在php板块找到了答案:
re = '/<pre>(.*?)<\/pre>/s';


同时还要匹配任何非空白字符。
gnefgnehz 2011-07-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fibbery 的回复:]

你可能是需要多行匹配。
[/Quote]

我试了下多行匹配,貌似也不行,小弟初学者,还望高人指点~
fibbery 2011-07-14
  • 打赏
  • 举报
回复
你可能是需要多行匹配。

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧