日期:2014-05-17 浏览次数:20732 次
<[aA]\s+((\w+\s*=\s*("([^"]*)"|'([^']*)'|([^'">\s]+))\s+)*)(href\s*=\s*("([^"]*)"|'([^']*)'|([^'">\s]+)))((\s+\w+\s*=\s*("([^"]*)"|'([^']*)'|([^'">\s]+)))*)\s*>(.*?)</[aA]\s*>
protected void Unnamed1_Click(object sender, EventArgs e)
{
//正则
Regex reg = new Regex("<[aA]\\s+((\\w+\\s*=\\s*(\"([^\"]*)\"|'([^']*)'|([^'\">\\s]+))\\s+)*)(href\\s*=\\s*(\"([^\"]*)\"|'([^']*)'|([^'\">\\s]+)))((\\s+\\w+\\s*=\\s*(\"([^\"]*)\"|'([^']*)'|([^'\">\\s]+)))*)\\s*>(.*?)</[aA]\\s*>");
//输入内容
string matchStr = TextBox1.Text;
//此处可以完成任务(利用委托)
MatchEvaluator myEvaluator = new MatchEvaluator(ReplaceCC);
string aaa = reg.Replace(matchStr, myEvaluator);
//最后结果
Response.Write(aaa);
}
//在这里单独处理每一个匹配项
public string ReplaceCC(Match m)
{
string temp = m.Groups[9].Value + m.Groups[10].Value + m.Groups[11].Value;
string g18 = m.Groups[18].Value;
temp = "http://www.biaodashi.com?projectid=00000&userid=1111111&url=" + temp;
return "<a " + m.Groups[1].Value + " href=\" " + temp + "\" " + m.Groups[12].Value + ">" + g18 + "</><br/>";
}