Having trouble determining if a file name conforms to a specific convention as follows. Using regular expression in C# .Net 4.0.
Valid Format: xxxxT_SSS_sss[i]_t#y.png
where
// x = Any single character.
// T = Digit: 1 to 7 inclusive.
// _SSS = Positive Integer: 000 to 999 inclusive. Always padded with leading zeros.
// _sss = Positive Integer: 000 to 999 inclusive. Always padded with leading zeros.
// i = Random text of any length including any characters. Will always be enclosed in square [] brackets. Optional.
// _t = Positive Integer: 0 to 999 inclusive. Not padded. Optional.
// #y = Positive Integer: 0 to 999 inclusive. Not padded. Optional.
UPDATE
Valid file names:
File1_000_000.png
File1_000_000_1.png
File1_000_000#2.png
File1_000_000_1#2.png
File1_000_000[text].png
File1_000_000[text]_1.png
File1_000_000[text]#2.png
File1_000_000[text]_1#2.png
The regex I've been trying is:
^(.{4}\\d_\\d{3}_\\d{3}(\\[\\w\\s]+\\])?(_\\d{1,3})?(\\#\\d{1,3})?)
This returns true for all the sample file names BUT, if I change File1_000_000[text]_1#2.png to File1_000_000[text]_#2.png by deleting the digit 1, it still returns true. The underscore is a part of the _t.