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
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
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
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 ***
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