注册 登录
编程论坛 VB.NET论坛

正则表达式对字符串2次提取更改问题

电脑白菜 发布于 2010-03-20 22:49, 906 次点击
代码如下:
        Dim reader As StreamReader = New StreamReader(httpResp.GetResponseStream, System.Text.Encoding.GetEncoding("UTF-8"))
        Dim respHTML As String = reader.ReadToEnd() 'respHTML就是网页源代码
        Dim strRegex As String = "(?<=<div id=""washinglist"">\s*).*?(?=\s*</div>)(?is)" '这就是表达式
        Dim r As System.Text.RegularExpressions.Regex
        Dim m As System.Text.RegularExpressions.MatchCollection
        r = New System.Text.RegularExpressions.Regex(strRegex, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
        m = r.Matches(respHTML)
        If r.IsMatch(strRegex) = True Then
            Dim i As Integer
            For i = 0 To m.Count - 1
               TextBox1.Text = TextBox1.Text + m.Item(i).Value + vbCrLf
            Next
        Else
            MsgBox("没有匹配内容!")
        End If
    End Sub
到了m = r.Matches(respHTML)这里m得到的内容并不是我要的,还要去除一些html标签。查了msdn,知道用replace方法进行修改代替,但是实在不知道如何写,新手,很多东西了解不深。

假如这里的找到匹配了,textbox1.text是:
<SPAN class=colorHs>红字:</SPAN>红 <BR>
<SPAN class=colorHs>蓝字:</SPAN>蓝 <BR>
<SPAN class=colorHs>黑字:</SPAN>黑

想用replace把“<SPAN class=colorHs>”代替为“<SPAN>”请问应该如何增加代码啊?
问题补充:
就是把m = r.Matches(respHTML)里面的每个组拿出来改。这里不知道怎么写啊,高手,跪求了。
3 回复
#2
电脑白菜2010-03-20 22:51
高手帮帮写个代码看看嘛,要是忙,那怕告诉个思路,指点出要用到什么方法,什么命名空间的类的也可以啊。
#3
wuyazhe2010-04-09 13:40
问题已解决了吧。都这么久了。如果还需要。你贴你的网址。
1