正则表达式查找字符串中的URL

可能重复:
C#代码用于链接字符串中的URL

我确定这是一个愚蠢的问题,但我无法在任何地方找到合适的答案。 我需要一个很好的URL正则表达式C#。 它需要查找字符串中的所有URL,以便我可以将每个URL包装在html中以使其可单击。

  1. 用于此的最佳表达方式是什么?

  2. 一旦我有了表达式,用正确格式化的对应物替换这些URL的最佳方法是什么?

提前致谢!

我现在正在使用它:

text = Regex.Replace(text, @"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)", "https://stackoverflow.com/questions/4750015/regular-expression-to-find-urls-within-a-string/$1"); 

使用此代码

 protected string MakeLink(string txt) { Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase); MatchCollection mactches = regx.Matches(txt); foreach (Match match in mactches) { txt = txt.Replace(match.Value, "https://stackoverflow.com/questions/4750015/regular-expression-to-find-urls-within-a-string/" + match.Value + ""); } return txt; }