
-----------------------------------
wtd
Sat Nov 13, 2004 11:04 pm

[Regex-tut] Nested Capturing Groups
-----------------------------------
Thus far...

As it is, I've only shown examples of capturing groups which are laid out linearly.  The previous example was:

/(['"])(.*)\1/

What if...

What if I want to match that entire thing, including the quotes?

/((['"]).*\2)/

Notice that the parentheses are now nested, and \1 has become \2.  This is because group 1 is now the entire thing.  Group 2 is the quote.

The simple rule

The opening parenthesis determines the number of the group.

Another group following:

((['"]).*\2)

Would be group 3.
