in reply to Regex dynamics

#!/usr/bin/perl my $q; $q = qr/(?:\[(?:(?>[^\[\]]+)|(??{$q}))*\])/; while ( defined( $_ = <DATA> ) ) { while (/(\w{1,2})($q)/g) { print $1, $2, $/; #push(@{$hash{$1}},$2); } } __DATA__ T[[pP]attern] X[] X[xx[xxx[xx]]]
Boris

Replies are listed 'Best First'.
Re: Re: Regex dynamics
by Hena (Friar) on Feb 11, 2004 at 09:16 UTC
    This is indeed what i wanted. Well it matches the [] as well, but that i can live with no problem :). Thank you.
      I did not read carefull enough. Try this line.
      my $q; $q = qr/(?:\[(?:(?>[^\[\]]+)|(??{$q}))+\])/;
      Boris
        Ah, my bad on last post :P. Meant that the [] are captured (not matched as written there).
        t[tag]: happens $1 == t $2 == [tag] instead of $1 == t $2 == tag
        My bad on explanations. I should be more careful on how to write (or think beforehand instead of just writing... :)).