日期:2014-05-17 浏览次数:20485 次
public String ReplaceLink(String pubh_desc) { System.Text.RegularExpressions.MatchCollection matchs = Regex.Matches(pubh_desc, "<a[^>]*href=(['\"]?)(?<url>(?:\\\\\"|[^\"'\\s>])*)\\1[^>]*>(?<text>[\\s\\S]*?)</a>", RegexOptions.IgnoreCase); for (int i = 0; i < matchs.Count; i++) { string str = matchs[i].Groups["url"].ToString(); if (!string.IsNullOrEmpty(str) && !str.Equals("#")) { String[] urls = str.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); String SpitUrl = String.Empty; if (urls != null && urls.Length > 1) { SpitUrl = urls[1]; } pubh_desc = pubh_desc.Replace(matchs[i].Value, string.Format("<a href=\"javascript:void(0)\">{0}</a>", matchs[i].Groups["text"])); } } return pubh_desc; }