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
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})")
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.
精彩评论