in reply to RegExp madness

Two answers.

The simple one is that it doesn't work because \1 in a regular expression means (or tries to mean) "match whatever was captured in the first capturing parens right here". Where match means string match. And the attempt at specifying the count doesn't match the form of a repeated match, so the braces are interpolated literally. So your regular expression will match the string "5{5}".

The theoretical reason that it can't work because of how the regular expression engine works. It has to compile the regular expression, and then run it. At compilation time it has to figure out things like \d{5} because that changes what the regular expression engine compiles the expression to, and it doesn't know then that \1 will be 5. At run-time it can figure out the meaning of \1, but at run-time it only knows how to interpolate \1 in, not how to recompile the regular expression on the fly.