이 질문의 답변을 읽은 후 : C# regex pattern to extract urls from given string - not full html urls but bare links as well 정규식 일치를 사용하거나 문자열 분리 방법을 사용하여 문서에서 URL을 추출하는 가장 빠른 방법을 알고 싶습니다.C#, 정규식 또는 문자열 분할을 사용하여 문자열 추출
그래서 html 문서가 포함 된 문자열이 있으며 URL을 추출하고 싶습니다.
정규식 방법은 다음과 같습니다
Regex linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
string rawString = "house home go www.monstermmorpg.com nice hospital http://www.monstermmorpg.com this is incorrect url http://www.monstermmorpg.commerged continue";
foreach(Match m in linkParser.Matches(rawString))
MessageBox.Show(m.Value);
그리고 문자열 분할 방법 :
string rawString = "house home go www.monstermmorpg.com nice hospital http://www.monstermmorpg.com this is incorrect url http://www.monstermmorpg.commerged continue";
var links = rawString.Split("\t\n ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("http://") || s.StartsWith("www.") || s.StartsWith("https://"));
foreach (string s in links)
MessageBox.Show(s);
그것을 할 수있는 가장 성능이 좋은 방법이다?
당신이 내 첫번째 생각 이었다는 것을 인정하는 것을 부끄러워 해요 스톱워치 –
으로 모두를 시도 할 수는 '내가 할 수있는 –
"스톱워치는 벤치 마크 프로그램의 몇 가지 유형입니다" 몇 일 동안 PC에 액세스 할 수 없기 때문에 벤치마킹 할 수 없었습니다. –