Quote:
Originally Posted by Jade Aislin
While I was looking up the reference you gave me, the 'unmatched group' seemed to resolve itself. However, I am still getting the 'invalid group reference'. I tried looking it up and it looked like it might be a problem with '$' when not used as an end of string reference. As far as I know my code only uses the $ to indicate the end of the string I want. Is that the only reason I would get that error?
|
The "unmatched group" issue is caused when a paren grouping is skipped, but used in the replacement. (Perl, etc automatically provide an empty string in that case.) "(a)?a" will match "a", but a replacement to "\1b" will fail. So we use "(|a)a" instead, which makes the paren group empty, but not skipped.
The "invalid group reference" is more basic--you're using \3 meaning the third paren group, but you only have 2 paren groups. Change it to \2.