Advertisement
vlad0

Strings 25 HTML Extract

Feb 3rd, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 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.  
  7. namespace _25.HTML
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string html = @"<html>   <head><title>News</title></head>   <body><p><a href=""http://academy.telerik.com"">Telerik Academy</a>aims to provide free real-world practical     training for young people who want to turn into     skillful .NET software engineers.</p></body> </html> ";
  14.            
  15.             string patternTitle = "<title>(.*?)</title>";
  16.             Console.WriteLine("Title: {0}", Regex.Match(html,patternTitle).Groups[1].ToString());
  17.  
  18.             string patternBody = "<body>(.*)</body>";
  19.             string patternInnerBody = ">(.*?)<";
  20.             string body = Regex.Match(html,patternBody).Groups[1].ToString();
  21.             foreach (Match match in Regex.Matches(body,patternInnerBody))
  22.             {
  23.                 Console.Write(match.Groups[1].ToString());
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement