I need to match a string inside brackets. It may consist of a) name, b) exactly 8 digits or c) a+b combined with ':' between. So, to sum up:
named
12345678
named:12345678
are valid options, but these are not:
named:
:12345678
named12345678
I tried to reuse 'name' and 'dd' named groups to avoid repeating subpatterns. However, it seems that group cannot be referenced if it wasn't used before. It also seems that the same situation is with \1-like capture accessor.
My current solution:
"^\\((?:(?'name'[^\\d]+)|((?'dd'\\d{2}){4})|\\k<name>:\\k<dd>)\\)$"
'dd' group is splitted into 2-digits chunks as I needed to parse it that way. C# flavour used.
Any ideas how to write it in an elegant, working way?