C# 如何从文本中获取URL
如何从文本中获取URL 例如:C# 如何从文本中获取URL,c#,asp.net,C#,Asp.net,如何从文本中获取URL 例如: string Text = "this is text with url http://test.com"; 我必须获取url并将其设置为其他变量。如何使用ASP.NET实现这一点 reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; 这是从文本中查找URL的正则表达式 希望对您有所帮助。您可以使用 string _Url = "this is t
string Text = "this is text with url http://test.com";
我必须获取url并将其设置为其他变量。如何使用ASP.NET实现这一点
reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
这是从文本中查找URL的正则表达式
希望对您有所帮助。您可以使用
string _Url = "this is text with url http://test.com";
MatchCollection _Match = Regex.Matches(_Url , @"http.+)([\s]|$)");
string _Address= _Match[0].Value.ToString();
/http | https | ftp | ftps\://[a-zA-Z0-9-.]+[a-zA-Z]{2,3}/\S*/
作为搜索的正则表达式。。。
; String.Split方法字符串[],StringSplitOptions <>你可以找到例子:C-C++ +F-VB [ComVisibleAttributefalse] 公共字符串[]拆分 字符串[]分隔符, StringSplitOptions选项
在这种情况下,http://可以用作分隔符。添加到前面的答案中,您也可以这样做:
string text = "this is text with url http://test.com";
Match match = Regex.Match(text, @"http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$");
// gets you http://test.com
string url = match.Value;
接下来做一点研究
string url = Text.Substring(Text.IndexOf("http://"));