Numbering Regex Submatches

Posted by gentlylisped on Stack Overflow See other posts from Stack Overflow or by gentlylisped
Published on 2008-09-17T20:33:05Z Indexed on 2010/05/10 2:38 UTC
Read the original article Hit count: 284

Is there a canonical ordering of submatch expressions in a regular expression?

For example: What is the order of the submatches in
"(([0-9]{3}).([0-9]{3}).([0-9]{3}).([0-9]{3}))\s+([A-Z]+)" ?

a. (([0-9]{3})\.([0-9]{3})\.([0-9]{3})\.([0-9]{3}))\s+([A-Z]+)  
   (([0-9]{3})\.([0-9]{3})\.([0-9]{3})\.([0-9]{3}))  
   ([A-Z]+)  
   ([0-9]{3})  
   ([0-9]{3})  
   ([0-9]{3})  
   ([0-9]{3})  

b. (([0-9]{3})\.([0-9]{3})\.([0-9]{3})\.([0-9]{3}))\s+([A-Z]+)  
   (([0-9]{3})\.([0-9]{3})\.([0-9]{3})\.([0-9]{3}))  
   ([0-9]{3})  
   ([0-9]{3})  
   ([0-9]{3})  
   ([0-9]{3})  
   ([A-Z]+)

or

c. somthin' else.

© Stack Overflow or respective owner

Related posts about regex

Related posts about linearization