MrMistreater

Extract URLs from text

Apr 13th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.38 KB | None | 0 0
  1. public static List<string> ExtractUrls(string source)
  2. {
  3.     // match.Groups["name"].Value - URL Name
  4.     // match.Groups["url"].Value - URI
  5.     const string regexPattern = @"<a.*?href=[""'](?<url>.*?)[""'].*?>(?<name>.*?)</a>";
  6.     var matches = Regex.Matches(source, regexPattern, RegexOptions.IgnoreCase);
  7.     return (from Match match in matches select match.Groups["url"].Value).ToList();
  8. }
Advertisement
Add Comment
Please, Sign In to add comment