有这么一段代码:有用正则表达式匹配一个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')" >,也就是说我通过匹配提取该html语言中的:“消息内容”“15206”,用vb语言的
而我在正则写的代码是也就是匹配代码:
    Dim MyReg As RegExp
    Dim MyReg1 As RegExp
    Dim objTemp  As MatchCollection        
    Dim i As Integer
    Set MyReg1 = New RegExp    
    MyReg1.IgnoreCase = True
    MyReg1.Global = True
    MyReg1.MultiLine = True 
    Set MyReg = New RegExp    
    MyReg.IgnoreCase = True
    MyReg.Global = True
    MyReg.MultiLine = True    
    MyReg.Pattern = "<td width=\"60%\" class=\"tdl\">(.*)<\/td>"和
    MyReg.Pattern = "<input type=\"checkbox\" name=\"fr_checker_(\d+)\" onclick=\"marqueeShow\(\'(\d+)\'\)\" >"
但鼠标一离开就提示缺少语句错误,在正则里是可以这样匹配的,但用在vb程序中就出现错误提示,以前用正则匹配函数在vb中用这样的格式可以,但这个却不行啊,麻烦各位高手指点,小弟感激不尽,解决立即给分,谢谢

解决方案 »

  1.   

    //鼠标一离开就提示缺少语句错误字符串的问题将MyReg.Pattern = "<td width=\"60%\" class=\"tdl\">(.*)<\/td>"
    修改为:
    MyReg.Pattern = "<td width=\""60%\"" class=\""tdl\"">(.*)<\/td>"
    其余类似,简单的说,就是字串中的一个",要用两个"代替
      

  2.   

    首先建议楼主先把这两个字符串提取出来,
    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 Functionstr = "<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
      

  3.   

    此贴到此为止,等xiaolei1982(小磊)再另一个贴帮我解决或一起给分,谢谢xiaolei1982(小磊) ,麻烦你再帮我想想我刚在另一个贴所说的情况