很急啊,请大家帮忙看看,正则表达式匹配html的问题
有用正则表达式匹配一个html标记: " <(.*)> .* <\/\1> "这个怎么用于匹配标记语言: <tr class= "hover " bgcolor= "#f5deb3 " >
<td width= "5% " class= "tdH "> 1 </td>
<td width= "60% " class= "tdl "> 消息内容!! </td>
<td width= "5% " class= "tdH "> - </td>
<td width= "5% " class= "tdH "> ok </td>
<td width= "5% " class= "tdH "> - </td>
<td width= "5% " class= "tdH "> 有效 </td>
<td width= "15% " class= "tdH ">
<a href= "?edit=15206&this_language=simplified&fr_show=1 "> 修改 </a>
/ <a href= "?act=0&annix=15206&this_language=simplified&fr_show=1 "> 停用 </a>
/ <a href= "?alert=15206&this_language=simplified&fr_show=1 "> 戒备 </a>
/ <a href= "?del=15206&this_language=simplified&fr_show=1 "> 删除 </a>
</td>
<!-- [DTS 460] - 01/03/2006 (Teh) Add on a checkbox for marquee function START -->
<td>
<input type= "checkbox " name= "fr_checker_15206 " onclick= "marqueeShow( '15206 ') " >
</td>
<!-- [DTS 460] - 01/03/2006 (Teh) Add on a checkbox for marquee function END -->
</tr> 中的 <td width= "60% " class= "tdl "> 消息内容!! </td> 和 <input type= "checkbox " name= "fr_checker_15206 " onclick= "marqueeShow( '15206 ') " > ,也就是说我通过匹配提取该语言中的:消息内容和数字15206,用vb语言的,请高手帮我解决解决,小弟感激不尽,解决立即给分,很急啊
[解决办法]
这里的人不知道用没用过VB……如果你用的是VB6,可以去开发语言-> VB版问下,VB.NET可以去.NET技术-> VB.NET。
至于匹配的正则表达式,可以试试:
<td width=\ "60%\ " class=\ "tdl\ "> (.*) <\/td>
<input type=\ "checkbox\ " name=\ "fr_checker_(\d+)\ " onclick=\ "marqueeShow\(\ '(\d+)\ '\)\ " >
但是怎么用在VB里就不知道了。
[解决办法]
MyReg.Pattern = " <td width= " "60% " " class= " "tdl " "> (.*) </td> "
再试下能否编译通过。
[解决办法]
Function func_RegExpTest1(patrn, strng) As Boolean '正ze表da式匹配操作(?找个数)
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(strng)
For Each Match In Matches
str1 = str1 & Match.Value
Next
MsgBox str1
End Function
然后:
Function func_ReplaceTest(patrn, replStr, str As String) '正ze表da式匹配操作(替?)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
regEx.Execute (str)
str2 = regEx.Replace(str, replStr)
func_ReplaceTest = True
End Function
str = " <td width= " "60% " " class= " "tdl " "> ([^> ]*) </td> | <input type= " "checkbox " " name= " "fr_checker_(\d+) " " "
call func_RegExpTest1(str, "楼主的html文本 ")
Call func_ReplaceTest(str, "$1$2 ", str1)
msgbox str2
[解决办法]
<input type= "checkbox " name= "fr_checker_(\d+) " | <td width= "60% " class= "tdl "> ([^> ]*) </td> 匹配得到
<td width= "60% " class= "tdl "> 消息内容!! </td> <input type= "checkbox " name= "fr_checker_15206 " 这个就是str1
然后对这个进行$1$2的替换,
今晚我只能帮你这么多,因为没发测试给你个表达试测试器研究一下
http://www.regexlab.com/zh/workshop.asp?pat=%3Cinput%20type%3D%22checkbox%22%20name%3D%22fr%5Fchecker%5F%28%5Cd%2B%29%22%20%7C%3Ctd%20width%3D%2260%25%22%20class%3D%22tdl%22%3E%28%5B%5E%3E%5D%2A%29%3C%2Ftd%3E&rto=%241%242&txt=%0D%0A%3Ctd%20width%3D%2260%25%22%20class%3D%22tdl%22%3E%u6D88%u606F%u5185%u5BB9%21%21%3C%2Ftd%3E%3Cinput%20type%3D%22checkbox%22%20name%3D%22fr%5Fchecker%5F15206%22%20&dlt=0
这个就是我给你匹配的看看