in reply to Re: PERL STRING QUESTION
in thread PERL STRING QUESTION
my ($before, $after) = $seq =~ /(..)$find(..)/;
... will find only one instance of a sub-sequence in a sequence. The following will find multiple instances of sub-sequences, either overlapping or non-overlapping:
>perl -wMstrict -le "my $seq = 'atggggtaggggat'; my $find = 'ggg'; print 'non-overlapping:'; while ($seq =~ m{ (..) $find (..) }xmsg) { print qq{($1)$find($2)}; } print 'overlapping:'; while ($seq =~ m{ (?= (..) $find (..)) }xmsg) { print qq{($1)$find($2)}; } " non-overlapping: (at)ggg(gt) (ag)ggg(at) overlapping: (at)ggg(gt) (tg)ggg(ta) (ta)ggg(ga) (ag)ggg(at)
|
|---|