Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET:转换html超链接中的普通超链接_Asp.net_Javascript - Fatal编程技术网

ASP.NET:转换html超链接中的普通超链接

ASP.NET:转换html超链接中的普通超链接,asp.net,javascript,Asp.net,Javascript,任何人都知道如何“发现”某些文本中的超链接,并使用asp.net(或javascript)将该超链接转换为html超链接。 例如,如果用户输入以下文本: 您在http://www.foo.com 如何在html中查找和转换,如: 您在 ?? 提前感谢您应该能够很容易地使用正则表达式 string InsertHyperLinks(string input) { string pattern = @"((https?|ftp|gopher|telnet|file|notes|ms-help

任何人都知道如何“发现”某些文本中的超链接,并使用asp.net(或javascript)将该超链接转换为html超链接。 例如,如果用户输入以下文本:

您在http://www.foo.com

如何在html中查找和转换,如:

您在

??
提前感谢

您应该能够很容易地使用正则表达式

string InsertHyperLinks(string input)
{
    string pattern = @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
    Regex r = new Regex(pattern);
    MatchEvaluator myEvaluator = new MatchEvaluator(delegate(Match m) { return String.Format("<a href=\"{0}\">{0}</a>", m.ToString()); });
    return r.Replace(input, myEvaluator);
}
字符串插入超链接(字符串输入)
{
字符串模式=@“(https?| ftp | gopher | telnet | file | notes | ms help):((/)|(\\\\\)+[\w\d:\\@%/;$()~+-=\\\\.&]*);
正则表达式r=新正则表达式(模式);
MatchEvaluator myEvaluator=新的MatchEvaluator(委托(匹配m){返回字符串.Format(“,m.ToString());});
返回r.Replace(输入,赋值器);
}
从这里取正则表达式

基于此示例使用MatchEvaluator