Outside a character class, a backslash followed by a digit greater than 0 (and possibly further digits) is a back reference to a capturing subpattern earlier (i.e. to its left) in the pattern, provided there have been that many previous capturing left parentheses.
However, if the decimal number following the backslash is less than 10, it is always taken as a back reference, and causes an error only if there are not that many capturing left parentheses in the entire pattern. In other words, the parentheses that are referenced need not be to the left of the reference for numbers less than 10. A "forward back reference" can make sense when a repetition is involved and the subpattern to the right has participated in an earlier iteration.
\n
explained (n > 0
always):
n <= 9
: Always a back reference to then
th group (no matter where the capturing group is). Results in an error if there are fewer thann
capturing groups.n >= 10
: Only a back reference if there are at leastn
number of capturing groups (starting) before it. Otherwise it's an escape sequence as in regular strings.