C# Regex for rss

C#

Public Domain

Regex pour lire un flux rss

Download (right click, save as, rename as appropriate)

Embed

Tags:

regex rss
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Code from http://regex.codes-sources.com/codes/UTILISATION-REGEXP-LIRE-FLUX-RSS_49800.aspx
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication2
{
	class Program
	{
		static void Main(string[] args)
		{
			
			// Regex match
			RegexOptions options = RegexOptions.Singleline;
			Regex regex = new Regex(@"<item><title>(?<title>.*?)</title><description>(?<description>.*?)</description><category>(?<category>.*?)</category><link>(?<link>.*?)</link><pubDate>(?<pubDate>.*?)</pubDate><dc:creator>(?<creator>.*?)</dc:creator></item>", options);
			string input = @"<item><title>CODE POSTAUX CANADIEN</title><description>Valide un code postal canadien... Je sais pas quoi dire de plus mais ma description doit faire 100 chrs.</description><category>Divers</category><link>http://regex.codes-sources.com/codes/CODE-POSTAUX-CANADIEN_47986.aspx</link><pubDate>Wed, 17 Sep 2008 20:38:05 GMT</pubDate><dc:creator>zen69</dc:creator></item><item><title>DATE ANSI SQL</title><description>Valide le format de date ANSI SQL ""YYYY-mm-dd hh:mi:ss am/pm"""" + ""\r\n"" + @"""" + ""\r\n"" + @""Permet l'utilisation de ""/"", ""-"", "" "" pour délimités les dates de sorte que 2008-09-1</description><category>Date & Heure</category><link>http://regex.codes-sources.com/codes/DATE-ANSI-SQL_47985.aspx</link><pubDate>Wed, 17 Sep 2008 20:12:25 GMT</pubDate><dc:creator>zen69</dc:creator></item><item>";
			
			
			
			// Get matches
			MatchCollection matches = regex.Matches(input);
			
			for (int i = 0; i != matches.Count; ++i)
			{
				Console.WriteLine("title " + matches[i].Groups["title"].Value);
				Console.WriteLine("description " + matches[i].Groups["description"].Value);
				Console.WriteLine("link "+ matches[i].Groups["link"].Value);
				
				Console.WriteLine("pubDate "+ matches[i].Groups["pubDate"].Value);
				Console.WriteLine("creator "+ matches[i].Groups["creator"].Value);
			
			}
			
			Console.ReadLine();
		}
	}
}