首页 新闻 搜索 专区 学院

求一个正则表达式 C#的

0
悬赏园豆:50 [已解决问题] 解决于 2016-03-22 10:04


数据 :aaaabbb<div style="display:none">yyyy</div>
过滤后留下aaaabbb
过滤div和其内容

剧里局外的主页 剧里局外 | 初学一级 | 园豆:11
提问于:2016-03-21 17:22
< >
分享
最佳答案
0
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]);
}

 

收获园豆:50
jello chen | 大侠五级 |园豆:7096 | 2016-03-21 19:04

试了好像不行,我用这个了 。改造他人的。

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

 

剧里局外 | 园豆:11 (初学一级) | 2016-03-22 10:02

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

剧里局外 | 园豆:11 (初学一级) | 2016-03-22 13:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册