Reputation: 838
Given the string 12312112211212123
I can't understand why the following regex: (1.+)\1
matches
But this one doesn't: ((1.+)\1)
What is the explanation for this?
Upvotes: 2
Views: 51
Reputation: 338208
\1
refers to the first set of parentheses in the expression.
Think about it.
Upvotes: 2
Reputation: 8413
The second regex doesn't match, because the outer group is seen as group 1 and the inner group as group 2. To make it match, you would have to use ((1.+)\2)
.
Upvotes: 4