(?= ...)
Operador de ``trailing'' o ``mirar-adelante'' positivo.
Por ejemplo, /\w+(?=\t)/ solo casa una palabra si va seguida de un tabulador, pero el tabulador no formará parte de $&.
Ejemplo:
> cat lookahead.pl
#!/usr/bin/perl
$a = "bugs the rabbit";
$b = "bugs the frog";
if ($a =~ m{bugs(?= the cat| the rabbit)}i) { print "$a matches. \$& = $&\n"; }
else { print "$a does not match\n"; }
if ($b =~ m{bugs(?= the cat| the rabbit)}i) { print "$b matches. \$& = $&\n"; }
else { print "$b does not match\n"; }
> lookahead.pl
bugs the rabbit matches. $& = bugs
bugs the frog does not match
>
Compare la siguiente salida:
> perl -e 'print "$ARGV\n\t$&\n"
if (m{<a href=\"(.*?)\">(?=(.*?)</a>.*?<a href)}i)'
-wn ~/public_html/*.html
/home/pl/public_html/plindex.html
<a href="http://osr5doc.sco.com:1996/tools/CONTENTS.html">
/home/pl/public_html/plpracticas.html
<a href="http://nereida.deioc.ull.es/html/java.html#html">
con la obtenida en la sección 3.15.
Casiano Rodríguez León
