ASP实现网址的自动识别
发表于:2007-06-30来源:作者:点击数:
标签:
publicstaticstringAuto(stringstr) //========================// //www. //http:// //ftp:// //xx@xx.xx //mms:// //========================// { Reg=newRegex("([^\\]=])(http://[A-Za-z0-9\\./=\\?%\\-_~`@’’:+!]+)"); str=Reg.Replace(str,"$1ahref=
public static string Auto(string str)
//========================//
// www.
// http://
// ftp://
// xx@xx.xx
// mms://
//========================//
{
Reg = new Regex("([^\\]=>])(http://[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)");
str = Reg.Replace(str,"$1<a href=\"$2\" target=\"_blank\">$2</a>");
Reg = new Regex("^(http://[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)");
str = Reg.Replace(str,"<a href=\"$1\" target=\"_blank\">$1</a>");
Reg = new Regex("(http://[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)$");
str = Reg.Replace(str,"<a href=\"$1\" target=\"_blank\">$1</a>");
Reg = new Regex("([^\\]=>])(ftp://[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)");
str = Reg.Replace(str,"$1<a href=\"$2\" target=\"_blank\">$2</a>");
Reg = new Regex("^(ftp://[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)");
str = Reg.Replace(str,"<a href=\"$1\" target=\"_blank\">$1</a>");
Reg = new Regex("(ftp://[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)$");
str = Reg.Replace(str,"<a href=\"$1\" target=\"_blank\">$1</a>");
Reg = new Regex("([^\\]=>])(mms://[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)");
str = Reg.Replace(str,"$1<a href=\"$2\" target=\"_blank\">$2</a>");
Reg = new Regex("^(mms://[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)");
str = Reg.Replace(str,"<a href=\"$1\" target=\"_blank\">$1</a>");
Reg = new Regex("(mms://[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)$");
str = Reg.Replace(str,"<a href=\"$1\" target=\"_blank\">$1</a>");
Reg = new Regex("([a-z0-9_A-Z\\-\\.]{1,20})@([a-z0-9_\\-]{1,15})\\.([a-z]{2,4})");
str = Reg.Replace(str,"<a href=\"mailto:$1@$2.$3\" target=\"_blank\">$1@$2.$3</a>");
Reg = new Regex("([^/])(www.[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)");
str = Reg.Replace(str,"$1<a href=\"http://$2\" target=\"_blank\">$2</a>");
Reg = new Regex("^(www.[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)");
str = Reg.Replace(str,"<a href=\"http://$1\" target=\"_blank\">$1</a>");
Reg = new Regex("(www.[A-Za-z0-9\\./=\\?%\\-&_~`@’’:+!]+)$");
str = Reg.Replace(str,"<a href=\"http://$1\" target=\"_blank\">$1</a>");
return str;
}
原文转自:http://www.ltesting.net