- Montag 28.03.2011
- Mi, 23.03.11
- 21.03.2011 - 27.03.2011
How can I get with REGEX 28.03.2011, 23.03.11 and 21.03.2011?
Last one I can get with split and " -", but how about first two? Can I somehow read just numbers?
For that kind of problems I use Expresso - free and .NET compatible. (http://www.ultrapico.com/Expresso.htm)
\d{2}[.]\d{2}[.]\d{4} - simplest pattern without value check
You may also tell us more what you are actually trying to do :)
For numbers extraction:
Regex regex = new Regex("(?<day>\d{2})[.](?<month>\d{2})\[.](?<year>(\d{4}|\d{2}))", RegexOptions.CultureInvariant);
Match match = regex.Match("20.03.2011");
if (match.Success)
{
if (match.Groups["day"] != null)
{
string day = match.Groups["day"].value;
}
//etc.
}
You can get the individual dates with something like this:
(?<Day>\d{1,2})\.(?<Month>\d{1,2})\.(?<Year>(?:\d{4}|\d{2}))
I assume that's more useful than trying to strip out the 'Montag' and so on.
精彩评论