您的位置:首页 > 其它

ceshi

2012-02-04 16:53 323 查看
    string Resault = content;

            //清空代碼前後(普通代碼)

            string pattern = @"<div class=\""cnblogs_code\""((?!</?div[^>]*>).|\n)*(((?'TAG'<div[^>]*>)((?!</?div[^>]*>).|\n)*)+((?'-TAG'</div>)((?!</?div[^>]*>).|\n)*)+)*(?(TAG)(?!))</div>";

            Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);

            MatchCollection matches = rgx.Matches(Resault);

            string pattern1 = @"<pre.*>((?!</?div[^>]*>).|\n)*(((?'TAG'<div[^>]*>)((?!</?div[^>]*>).|\n)*)+((?'-TAG'</div>)((?!</?div[^>]*>).|\n)*)+)*(?(TAG)(?!))</pre>";

            Regex rgx1 = new Regex(pattern1, RegexOptions.IgnoreCase);

            MatchCollection matches1 = rgx1.Matches(Resault);

            if (matches.Count > 0)

            {

                for (int id = 0; id < matches.Count; id++)

                {

                    Resault = Resault.Replace(matches[id].Value, matches1[id].Value);

                }

            }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  regex string div class