2013-05-27 8 views
0

텍스트에서 URL을 가져 오는 방법은 무엇입니까? 예를 들어텍스트에서 URL을 가져 오는 방법

: 나는 URL을 얻고 다른 변수로 설정해야

string Text = "this is text with url http://test.com"; 

. 어떻게하면 ASP.NET에서이 작업을 수행 할 수 있습니까?

+1

는 정규식 패턴 – PiLHA

+3

http://stackoverflow.com/questions/5218863/find-url-in-plain를 사용하여 -text-and-insert-html-a-markups는 약간의 연구를합니다. – Liviu

답변

1

, 당신은뿐만 아니라이 작업을 수행 할 수 있습니다

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; 
1
reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; 

텍스트에서 URL을 찾는 정규식입니다.

호프가 도움이 되길 바랍니다. . // [. A-ZA-Z0-9-] + [A-Za-z]와 {: \ (FTPS | HTTPS | | FTP HTTP)

1
string _Url = "this is text with url http://test.com"; 

MatchCollection _Match = Regex.Matches(_Url , @"http.+)([\s]|$)"); 
string _Address= _Match[0].Value.ToString(); 
1

U는

"/를 사용할 수 있습니다 2,3} (/ \ S *)/"검색을위한 정규 표현식으로

... ;?)

1
string url = Text.Substring(Text.IndexOf("http://")); 
관련 문제