[General boards] [Fall 2018 courses] [Summer 2018 courses] [Winter 2018 courses] [Older or newer terms]

Regex question from slides



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”.


thanks for answering, I get it now


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.