tags:

views:

52

answers:

2

I have to process text file like that:

 2010-04-02
 ...
 ...
 ...
 2010-05-01
 ...
 ...
 ...

It is possible to get values by using Split function:

Regex.Split(text, @"\d{4}-\d{2}-\d{2}")

Is there way to get dates and related text below the date?

My output should be array of items (date, text).

Thanks

+1  A: 

Consider, instead, DateTime.Parse() and DateTime.ParseExact(). They're very efficient.

There's good reference here and here.

If you must use regular expressions, take a look at this. There are options for matching patterns in multi-line text.

kbrimington
+2  A: 

According to the docs, wrapping the string you're splitting on in () (making it a capture group) will result in these captures being included in the array.

Regex.Split(text, @"(\d{4}-\d{2}-\d{2})")

Will A