Q:

I keep getting .success as false

I have to read an excel file and check if its name follows a certain pattern.
The pattern is CDFSDDRCxxxCurryymmdd, where xxx is a number, Curr is either EUR or GBP and yymmdd is a date.
This is my file's name, CDFSDDRC603EUR120124.xls. Can also be .xlsx.
And this is my code.
Match nameIsValid = Regex.Match(activeWorkbook.Name,
@"CDFSDDRC(?<xxx>[0-9]+)(?<xxx>[A-Z]+)(?<yymmdd>[0-9][0-9][0|1][0-9][0-3][0-9])\.xls?");

I keep getting nameIsValid.success as false.
I think my Regex expression is ok, but then again.
Any ideas?
Rui Martins

A:

Your pattern for the date matching is somewhat messed up. It doesn't really match dates but just a weir combination of numbers. Also, you can't use | inside character classes. Think closely about how dates are constructed.
Furthermore, you have a duplicate matching group called xxx. This will surely mess up C#'s behaviour when accessing one of them.
Try this one
/CDFSDDRC(?<xxx>\d+)(?<curr>[A-Z]+)(?<yymmdd>\d{2}(?:0[1-9]|1[12])(?:(?:0|1|2)[1-9]|3[0-2]))\.xlsx?/

