Converting an URL to a link
-
Hey guys, I'm trying to create html links of all URL's in a string. I'm calling the function below which seems to be pretty close to my needs, except for when someone enters a link followed by text directly after the url. Somebody with a 'proven technology' solution?
public static string LinkText(string Input) { Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); string Output = urlregex.Replace(Input, "[$1](\"$1\")"); Regex emailregex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", RegexOptions.IgnoreCase | RegexOptions.Compiled); Output = emailregex.Replace(Output, "[$1](mailto:$1)"); return Output; }
I love it when a plan comes together http://www.zonderpunt.nl[^]
-
Hey guys, I'm trying to create html links of all URL's in a string. I'm calling the function below which seems to be pretty close to my needs, except for when someone enters a link followed by text directly after the url. Somebody with a 'proven technology' solution?
public static string LinkText(string Input) { Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); string Output = urlregex.Replace(Input, "[$1](\"$1\")"); Regex emailregex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", RegexOptions.IgnoreCase | RegexOptions.Compiled); Output = emailregex.Replace(Output, "[$1](mailto:$1)"); return Output; }
I love it when a plan comes together http://www.zonderpunt.nl[^]
Another RegEx is here: http://www.liamdelahunty.com/tips/php_convert_url_to_link.php[^]
Vasudevan Deepak Kumar Personal Homepage Tech Gossips