Chinaunix
标题:
[求助正则表达式] 匹配网页源码里面的字符串
[打印本页]
作者:
zhshb8511
时间:
2012-09-05 10:58
标题:
[求助正则表达式] 匹配网页源码里面的字符串
本帖最后由 zhshb8511 于 2012-09-06 00:36 编辑
正则匹配 正文内容,该怎么写呢
假如所有数据都已经 去除换行符后存储在$_了
@search_result = /\w*\s*\.*\w*/g;
;好像上面的写法是不对的
复制代码
就是下面html代码里面的 Table 1. Keyboard commands
<tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;page-break-inside:avoid'>
<td width=835 colspan=2 valign=top style='width:466.0pt;border:none;
border-bottom:solid windowtext 1.0pt;mso-border-bottom-alt:solid windowtext .5pt;
padding:0cm 5.4pt 0cm 5.4pt'>
<p class=T1TableTitleStandard><a name="KeyboardCommands_table"><span
lang=EN-US>Table </span></a><!--[if supportFields]><span style='mso-bookmark:
KeyboardCommands_table'></span><span style='mso-element:field-begin'></span><span
style='mso-bookmark:KeyboardCommands_table'><span lang=EN-US><span
style='mso-spacerun:yes'> </span>SEQ Table \r 1 \* MERGEFORMAT <span
style='mso-element:field-separator'></span></span></span><![endif]--><span
style='mso-bookmark:KeyboardCommands_table'><span lang=EN-US><span
style='mso-no-proof:yes'>1</span></span></span><!--[if supportFields]><span
style='mso-bookmark:KeyboardCommands_table'></span><span style='mso-element:
field-end'></span><![endif]--><span style='mso-bookmark:KeyboardCommands_table'></span><span
lang=EN-US>. Keyboard commands</span></p>
</td>
</tr>
复制代码
作者:
zhshb8511
时间:
2012-09-06 00:37
谁给看看呢,真是三天不读书,直接人变猪啊
作者:
justqb
时间:
2012-09-06 09:02
把 <[^>]+> 替换成空格,剩下的不就是我们在网页上看到的“正文”么?
不太明白楼主的意思。
作者:
zhshb8511
时间:
2012-09-06 10:23
回复
3#
justqb
谢谢你的回复
其实我想要的数据是 “Table 1. Keyboard commands”
作者:
justqb
时间:
2012-09-06 10:26
本帖最后由 justqb 于 2012-09-06 10:26 编辑
SEQ Table \r 1 \* MERGEFORMAT
这些为什么不要了呢?
作者:
mcshell
时间:
2012-09-06 10:43
<tr[\s\S]+?<p[^>]+><a\s*name=["']?(.*?)["]>
复制代码
取$1 ,,不过话说。我还是没怎么看懂你的需求
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2