I have a excel file that must have this name format, where xxx is a number, Curr is either EUR or GBP and yymmdd is a date.
CDFSDDRCxxxCurryymmdd.xls(x)
And this is the regex I’m using. It doesn´t works with dates like 120920 or 121005.
Any Ideas??
Match nameIsValid = Regex.Match(activeWorkbook.Name,
@"CDFSDDRC(?<xxx>\d+)(?<curr>EUR|GBP)(?<yymmdd>\d{2}(?:0[1-9]|1[12])(?:(?:0|1|2)[1-9]|3[0-2]))\.xls?");
A quick fix for this regex would be the following one:
You can check out the results here.
Note that this one will match if the day of the month is
00.My opinion is that you should not be checking for a valid days, months and years in your regex. You can match a 6-digit date by using the following, much simpler regex:
After you match it, you can then programmatically check whether it’s a valid date or not.