日期:2014-05-18 浏览次数:20807 次
string source = "www.a.aa.com/xxx.htm<a href='http://www.a.aa.com/xxx.htm'>xxx</a>"; Regex reg = new Regex(@"(?is)(?<!<a href[^>]*?)(?<v1>[^(href)]+)/([^<>]+).htm"); source = reg.Replace(source, "<a href='" + "${v1}" + "'target='_blank'>" + "${v1}"+"</a>"); MessageBox.Show(source);
------解决方案--------------------
yourhtml=Regex.Replace(yourhtml,@"(?i)(?<!<a\s+href=(['""])?(?:https?://)?)www\.[ab]\.(?:aa|bb)\.com[^'""<\s]+","<a href='$0' target='_blank'>$0</a>");