Re: Question on regexp grouping/capturing

2008-08-04 Thread op
shawnhcorey wrote: [...] > Note that because of its level of precedence, the >alteration applies to the whole pattern so $2 and $3 are undef when >'lang' is matched. [...] Ok, so my problem was actually getting the precedence of the '|'- operator wrong. So /(lang)|(id)="(\S+)"/g translates to :

Re: Question on regexp grouping/capturing

2008-08-04 Thread Rob Dixon
Mr. Shawn H. Corey wrote: > > Perl captures on a strict left-to-right policy. Start at the left of > the regular expression and every opening parenthesis will be captured in > the next numbered variable. For your first example: > > /(lang)|(id)="(\S+)"/g >^ ^ ^ >$1 $2

Re: Question on regexp grouping/capturing

2008-08-04 Thread John W. Krahn
op wrote: Hello, Hello, I thought I had understood regular expression grouping relatively well, untill I ran into the following behavior: perl -e ' my $string = ""; while ($string =~ /(lang)|(id)="(\S+)"/g) { print "\$1->|$1|, \$2->|$2|, \$3->|$3|\n"; } ' outputs: $1->||, $2->|id|, $3->|do

Re: Question on regexp grouping/capturing

2008-08-04 Thread Mr. Shawn H. Corey
On Mon, 2008-08-04 at 03:28 -0700, op wrote: > Hello, > I thought I had understood regular expression grouping relatively > well, untill I ran into the following behavior: > > perl -e ' > my $string = " lang=\"hindi\">"; > while ($string =~ /(lang)|(id)="(\S+)"/g) { > print "\$1->|$1|, \$2->|$2|

Question on regexp grouping/capturing

2008-08-04 Thread op
Hello, I thought I had understood regular expression grouping relatively well, untill I ran into the following behavior: perl -e ' my $string = ""; while ($string =~ /(lang)|(id)="(\S+)"/g) { print "\$1->|$1|, \$2->|$2|, \$3->|$3|\n"; } ' outputs: $1->||, $2->|id|, $3->|dontcare| $1->|lang|, $2-