var input = "aaaabbb<div style=\"display: none\">yyyy</div>"; var regex = new Regex(@"(.+)(?=<\s*div)"); var match = regex.Match(input); if (match.Success) { Console.WriteLine(match.Groups[1]); }
试了好像不行,我用这个了 。改造他人的。
Public Function FilterHtml(ByVal content As String) As String Dim returnstr As String = "" Try Dim pattern As String = "<div[^>]*>(.*?)</div>" Dim reg As Regex = New Regex(pattern, RegexOptions.IgnoreCase Or RegexOptions.Compiled Or RegexOptions.Multiline) returnstr = reg.Replace(content, "") Catch ex As Exception End Try Return returnstr End Function
Public Function FilterHtml(ByVal content As String) As String
Dim returnstr As String = ""
Try
Dim pattern As String = "<div style=""display:none""[^>]*>(.*?)</div>"
Dim reg As Regex = New Regex(pattern, RegexOptions.IgnoreCase Or RegexOptions.Compiled Or RegexOptions.Multiline)
returnstr = reg.Replace(content, "")
Catch ex As Exception
End Try
Return returnstr
End Function