in reply to Re: Regexp dashes at boundaries
in thread Regexp dashes at boundaries

The alternation meta-character | works on the two entities directly next to it.

Not in Perl:

$t = 'abcd'; $t =~ s/bc|xy/pq/; print "$t\n"; ==> apqd
If what you said were true, the match above would have failed, and the contents of $t would have remained unchanged.

the lowliest monk

Replies are listed 'Best First'.
Re^3: Regexp dashes at boundaries
by ww (Archbishop) on Mar 18, 2005 at 15:25 UTC
    and for possible further illumination:
    $t = 'abcd'; $t1 = 'ababxycdcd'; $t2 = 'ababxycdcd'; $t3 = 'ababxycdcd'; # same as $t2, which is identical to $t1 $t4 = 'ababxycdcd'; # still the same... $t =~ s/bc|xy/pq/; print "\$t is: $t\n"; $t1 =~ s/(ab|xy)/pq/; print "\$t1 is: $t1\n"; $t2 =~ s/(ab|xy)/pq/g; print "\$t2 is: $t2\n"; $t3 =~ s/(ab)|(xy)/pq/g; print "\$t3 is: $t3\n"; $t4 =~ s/((ab)|(xy))/pq\1/g; #capture regex -outer (); grouping () in +side print "\$t4 is: $t4\n"; =head1 OUT Output of C:\_perl\pl_test>perl 440581.pl $t is: apqd matched the 'b' $t1 is: pqabxycdcd parenthesdized the alt; now matches the FIRST +'ab' $t2 is: pqpqpqcdcd added /g (match globally) replaces both 'ab's +and the xy $t3 is: pqpqpqcdcd Shifting parens ==> no change, here $t4 is: pqabpqabpqxycdcd Capturing regex -- 3 'pq' pairs, each pair f +ol by 'ab' or 'xy' =cut
    additional example added