Allinav has asked for the wisdom of the Perl Monks concerning the following question:
To break the problem down I started with the example from perlre for the branch reset. The qr_test.pl contains the code above.#! /usr/bin/perl use warnings; use strict; my $String_to_test = $ARGV[0]; if ( !defined($String_to_test) || $String_to_test eq "") { die "please supply a string to test qr code agaist as first ar +guement\n"; } my $qrtest = eval ( $ARGV[1] ); if ( $@ ) { die "invalid qr supplied at arg2. caused the following error\n +$@\n"; } print "qr=$qrtest\n"; print "string=$String_to_test\n"; if ( $String_to_test =~ $qrtest ) { print "$qrtest present\n"; print "1=$1\n" if defined($1); print "2=$2\n" if defined($2); print "3=$3\n" if defined($3); print "4=$4\n" if defined($4); print "5=$5\n" if defined($5); print "6=$6\n" if defined($6); print "7=$7\n" if defined($7); print "8=$8\n" if defined($8); } else { print "$qrtest NOT present\n"; }
This does what is expected../qr_test.pl atuvz 'qr/ ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) + ( z ) /x' qr=(?x-ism: ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) ) string=atuvz (?x-ism: ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) ) presen +t 1=a 2=t 3=v 4=z
This does not do what is expected the 4th capture group should contain w not z and the 5th should contain z./qr_test.pl atuvwz 'qr/ ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) +(w) ) ( z ) /x' qr=(?x-ism: ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) (w) ) ( z ) ) string=atuvwz (?x-ism: ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) (w) ) ( z ) ) pr +esent 1=a 2=t 3=v 4=z
This crashes perl./qr_test.pl atuvwxz 'qr/ ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) + (w) (x) ) ( z ) /x' qr=(?x-ism: ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) (w) (x) ) ( z + ) ) string=atuvwxz (?x-ism: ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) (w) (x) ) ( z ) +) present 1=a 2=t ./qr_test.sh: line 11: 40158 Segmentation fault
This works so I have a work around../qr_test.pl 'atuvwxz' 'qr/ ( a ) (?| x ( y ) z | (p (q) r) | (t) u ( +v) (w) (x) ) ( z ) /x' + ./qr_test.pl atuvwxz 'qr/ ( a ) (?| x ( y ) z () () ()| (p (q) r) | + (t) u (v) (w) (x) ) ( z ) /x' qr=(?x-ism: ( a ) (?| x ( y ) z () () ()| (p (q) r) | (t) u (v) (w) ( +x) ) ( z ) ) string=atuvwxz (?x-ism: ( a ) (?| x ( y ) z () () ()| (p (q) r) | (t) u (v) (w) (x) +) ( z ) ) present 1=a 2=t 3=v 4=w 5=x 6=z
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex with capture groups and branch reset crashes perl
by choroba (Cardinal) on Dec 11, 2015 at 13:04 UTC | |
|
Re: regex with capture groups and branch reset crashes perl
by mr_mischief (Monsignor) on Dec 11, 2015 at 14:58 UTC | |
by AnomalousMonk (Archbishop) on Dec 11, 2015 at 18:39 UTC | |
|
Re: regex with capture groups and branch reset crashes perl
by Anonymous Monk on Dec 11, 2015 at 14:00 UTC |