From: akopa
Subject: Numbering Regex Submatches
Date: 
Message-ID: <d10ead4f-f729-42d0-bf2b-8190e502940a@73g2000hsx.googlegroups.com>
Is there a canonical ordering of submatch expressions in a regular
expression? (tangentially related as I am writing a small regex engine
in lisp)?

For example: What are 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.

Matt

From: akopa
Subject: Re: Numbering Regex Submatches
Date: 
Message-ID: <c06d4dc1-91bb-4aeb-9b98-55a3ec6cf084@l43g2000hsh.googlegroups.com>
On Sep 17, 2:38 pm, akopa <··················@gmail.com> wrote:
> Is there a canonical ordering of submatch expressions in a regular
> expression? (tangentially related as I am writing a small regex engine
> in lisp)?
>
> For example: What are the order

s/What are/What is
From: akopa
Subject: Re: Numbering Regex Submatches
Date: 
Message-ID: <6f8e4009-5aa7-4592-b12b-efb822cf1bda@59g2000hsb.googlegroups.com>
On Sep 17, 2:38 pm, akopa <··················@gmail.com> wrote:
> Is there a canonical ordering of submatch expressions in a regular
> expression? (tangentially related as I am writing a small regex engine
> in lisp)?
>
> For example: What are the order of the submatches in "(([0-9]{3})\.
> ([0-9]{3})\.([0-9]{3})\.([0-9]{3}))\s+([A-Z]+)" ?


according to the crowd at stackoverflow (http://stackoverflow.com/
questions/87330/numbering-regex-submatches), it is

> 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]+)

Matt
From: Barry Margolin
Subject: Re: Numbering Regex Submatches
Date: 
Message-ID: <barmar-01E5A2.17082317092008@newsgroups.comcast.net>
In article 
<····································@73g2000hsx.googlegroups.com>,
 akopa <··················@gmail.com> wrote:

> Is there a canonical ordering of submatch expressions in a regular
> expression? (tangentially related as I am writing a small regex engine
> in lisp)?

I believe the rule is that you simply number the left parentheses from 
left to right.

> 
> For example: What are 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.
> 
> Matt

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: John Thingstad
Subject: Re: Numbering Regex Submatches
Date: 
Message-ID: <op.uhm52yhvut4oq5@pandora.alfanett.no>
P� Wed, 17 Sep 2008 21:38:30 +0200, skrev akopa  
<··················@gmail.com>:

> Is there a canonical ordering of submatch expressions in a regular
> expression? (tangentially related as I am writing a small regex engine
> in lisp)?
>
> For example: What are 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.
>
> Matt

To evade the question. get a copy of the regexp coach and see for youself.
http://www.weitz.de/regex-coach/

--------------
John Thingstad