Hypothesis: somewhere in your matching groups, there is a valid group reference in the form "$n"
where n
cannot match any group in the original Pattern
.
Hence the error: "illegal group reference".
Solution: use "$2"
instead of concatenating .group(2)
etc.
Ie instead of writing:
"\\\\pochhammer{"+ pochhammer.group(2) + "}{" + pochhammer.group(3) + "}"
write:
"\\\\pochhammer{$2}{$3}"
Side note: no need to escape parens in a character class; [^)]
works just as well as [^\)]
, and it is easier to read ;)