I am trying to use c# Regular Expression to match a particular string of characters but I can not figure out how to do it. Any help is appreciated.
The string that I am trying to match is as follows, where A is an uppercase alpha character, X is an upper case alpha-numeric character and # is 0, 1 or 2.
AA-#-XX-X-XXX-XXXXXXX-XXXXXXXX
So any of the following would match the string above.
XY-1
MM-0-AB
MM-0-AB-1-ABC-1234567
VV-2-XX-7-CCC-ABCDEFG-12345678
Any any of the following would NOT match.
QQ-7-AA (Only 0, 1, 2 are allowed at the second level.)
QQ-2-XX-7-CC (Partial characters for that level.)
QQ-2-XX-7-CCC-ABCDEFG- (Can not end in a dash.)
QQ-2-XX-7-CCC-ABCDEFG-123456 (Partial characters for that level.)
So far (not that far really) I have as the pattern to match @"^[A-Z]{2}", but I am unsure how to match conditionally (I'm not even sure if conditionally is the proper term to use) the rest of the string, but only if it is there. Do I need to write 7 different statements for this? Seems unreasonable, but I could be wrong.