Perl pattern matching with zero width assertion

Posted by Simone on Stack Overflow See other posts from Stack Overflow or by Simone
Published on 2010-03-27T10:58:43Z Indexed on 2010/03/27 11:03 UTC
Read the original article Hit count: 301

Filed under:
|
|

Hi everyone,

I can't get why this code work:

$seq = 'GAGAGAGA';
my $regexp = '(?=((G[UCGA][GA]A)|(U[GA]CG)|(CUUG)))'; # zero width match
while ($seq =~ /$regexp/g){ # globally
     my $pos = pos($seq) + 1; # position of a zero width matching
     print "$1 position $pos\n";
}

I know this is a zero width match and it dosn't put the matched string in $&, but why does it put it in $1?

thank you!

© Stack Overflow or respective owner

Related posts about perl

Related posts about matching