regexReplaced n = do
char 'T'
spaces
x <- concat (replicateM n alphaNum)
y <- concat (many alphaNum)
spaces
char '='
return (x ++ y)
The above is a Haskell function that does the parsing required above, returning the alphanumeric characters if the parse succeeds and returning an error if it does not. You may not speak Haskell, but this is probably still more readable than (n) => {new RegExp(`T\s(\w{${n}}\w)\s*=`)}, which is the Javascript function that does a similar thing.