In a Python match pattern, how do I match a literal digit like 1 after a backreference by number like \1?
I tried the \g<1> syntax that is available in substitution patterns for this purpose, but it doesn’t work in my match pattern.
I have a larger problem that I want to solve using a function that will perform the following somewhat unusual task. The task is to construct patterns dynamically so that each pattern will match digit sequences that have repeated digits in certain positions and specific digits in the remaining positions.
I noticed that I don’t need the
\g<1>syntax. Instead I can use one of several techniques to separate the numeric backreference like\2from the digit like9that follows it. Here are three such techniques:(?:\2)9\2{1}9\2[9]