Dax Mickelson schreef: > I am having problems matching ALL possible matches of a string against > another (very large) string. I am doing something like: @LargeArray > = ($HugeString =~ m/$Head......../ig); Where $Head is an 8 character > string. (Basically I want to get all 16 character long substrings > out of $HugeString where the first 8 characters match $Head.) > > My problem comes about when (for example) I want to match a 16 > character string that starts with AAAAAAAA. Suppose > $HugeString=AAAAAAAAAASDFGHJKL and $Head=AAAAAAAA I want > @LargeArray[0]=AAAAAAAAAASDFGHJ, @LargeArray[1]=AAAAAAAAASDFGHJK, and > @LargeArray[2]=AAAAAAAASDFGHJKL > > Right now I would only get @LargeArray[0]=AAAAAAAAAASDFGHJ > > What am I doing wrong? How do I get all matches?
The startpoint (for the next iteration) is beyond the last match. You want the startpoint to move only one position with each match. There are several ways to do that. One way is to use zero-width look-behind and look-ahead assertions (see perldoc perlre). #!/usr/bin/perl use strict; use warnings; { local ($,, $\) = (':', "\n"); $_ = 'xxxxAAAAAAAAAASDFGHJKLxxxx'; my $Head = 'AAAAAAAA'; print $Head, $1, substr($',0,7) while /(?<=$Head)(.)(?=.{7})/ig; } (remove the colon from '$,' when you grok it) -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>