private string ReplaceKeyWord(string content)
    
{
        
string keyword = @"<(\ba\b)[^>]*>[\w\W]*?</\1 *>|AA|BBB|CCC";
        
return Regex.Replace(content, keyword, ReplaceString, RegexOptions.IgnoreCase);

    }

    
private string ReplaceString(Match m)
    
{
        
if (Regex.IsMatch(m.ToString(), @"<(\ba\b)[^>]*>[\w\W]*?</\1 *>", RegexOptions.IgnoreCase))
        
{
            
return m.ToString();
        }

        
else
        
{
            
return "<a href=\"aaa.aspx?keyword=" + m.ToString() + "\">" + m.ToString + "</a>";
        }

    }

<(\ba\b)[^>]*>[\w\W]*?</\1 *>为 <a href="...">XXXXX</a> 的正则表达式
在关键词正则表达式前 加一个超链接正则表达式,在替换的时候,如果是超链接就不替换
posted on 2007-08-20 18:53  蓝色爬虫  阅读(604)  评论(1编辑  收藏  举报