Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Regex-tut] Nested Capturing Groups
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Sat Nov 13, 2004 11:04 pm   Post subject: [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:

code:
/(['"])(.*)\1/


What if...

What if I want to match that entire thing, including the quotes?

code:
/((['"]).*\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:

code:
((['"]).*\2)


Would be group 3.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: