I have a bunch of files that need to be parsed, and they all have one of two date patterns in the file name (we're upgrading our system, and we need to have the file parser be able to recognize both date formats, new and old).
The filenames look like either <fileroot>_yyyyMMdd.log
or <fileroot>_MMddyy.log
, and I need to be able to parse out the numbers to parse the dates, however, whenever I try to use a regular expression like ^.*(\\d{6,8}).*$
or ^.*(\\d{6}|\\d{8}).*$
to parse out the numbers of the date, the capture group is always 6 characters in length, even for the file names that are 8 digits.
Is there any way to force the regular expression library in C# to be as exhaustive as possible in trying to match a regular expression? I know how to do it in Java, just not C# / .NET, I'm pretty new at the language.