^(([ab])c)\2\1$

what is the first group and second group here?

I don’t get how acaac and bcbbc matches this expression

^(([ab])c)\2\1$

what is the first group and second group here?

I don’t get how acaac and bcbbc matches this expression

I believe the trick is with the positioning of the parantheses so first what the regex checks for is an expression which contains “a” or “b” followed by a “c”. If you notice the way the parantheses are placed ((ab)c) is the first part and (ab) is within it. So then it’s checking for the second part followed by the first. So ac then just a then ac again which gives you “acaac” is valid. Similarly, bc then just b then bc again which gives you “bcbbc”.

Groups are numbered in the same order as their open parenthesis appears from left to right.

So (a(b©)) has three groups. \1 refers to the entire expression. \2 refers to the bc and \3 is just c.