如何从文本中获取URL?如何从文本中获取URL
例如:
string Text = "this is text with url http://test.com";
我一定要得到URL,并将其设置为其他变量。我怎样才能用ASP.NET做到这一点?
如何从文本中获取URL?如何从文本中获取URL
例如:
string Text = "this is text with url http://test.com";
我一定要得到URL,并将其设置为其他变量。我怎样才能用ASP.NET做到这一点?
添加到以前的答案,你可以这样做,以及:
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;
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();
U可以使用
“/(HTTP | HTTPS | FTP | FTPS)\:// [A-ZA-Z0-9-。] + [A-ZA-Z] {。 2,3}(/ \ S *)/”
为您搜索的正则表达式... ;?)
String.Split方法(String [],StringSplitOptions)
http://msdn.microsoft.com/en-us/library/tabh47cf.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
你可以找到例子:C# - C++ - F# - VB
[ComVisibleAttribute(假)
公共字符串[]斯普利特(
的String []分隔符,
StringSplitOptions选项
)
在这种情况下,“http://”对于分隔符来说可以是一个很好的字符串。
string url = Text.Substring(Text.IndexOf("http://"));
使用正则表达式模式 – PiLHA
http://stackoverflow.com/questions/5218863/find-url-in-plain -text-and-insert-html-a-markups接下来做了一些研究 – Liviu