Advertisement
Guest User

Regex

a guest
Oct 9th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. class ExtractHyperLinks
  9. {
  10.     static void Main(string[] args)
  11.     {
  12.         string text = string.Empty;
  13.         string input = Console.ReadLine();
  14.         while(input != "END")
  15.         {
  16.             text += input;
  17.             input = Console.ReadLine();
  18.         }
  19.  
  20.         string pattern = @"(?<=<a)(.+)\s?href\s*=\s*(""|')(.+?)(\2)";
  21.         Regex hrefSearch = new Regex(pattern);
  22.         MatchCollection matches = hrefSearch.Matches(text);
  23.         foreach (Match match in matches)
  24.         {
  25.             Console.WriteLine(match.Groups[3].Value);
  26.         }
  27.  
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement