On Fri, 27 Sep 2002, nkuipers wrote:

> Hello,
> 
> I am trying to get the positions of every instance of a given substring within 
> a given superstring (DNA sequence), and currently have a
> 
> while ( $super_string =~ m/${sub_string}/gi ) { ... }
> 
> construct.
> 
> I was under the impression that the regex transmission would bump along every 
> character and try to match, backtracking even after success to try the 
> character after the first character from the successful match.  However, The 
> Camel 3rd says that "used in a scalar context, the /g modifier...makes Perl 
> start the next match on the same variable at a position just past where the 
> last one stopped"(p151).  This is obviously inadequate in cases where one 
> match may commence within another.
> 
> Suggestions?

>From the perl cookbook, page: 162
#!/usr/bin/perl -w
use strict;

my $digits = '123456789';
my @yeslap = $digits =~ /(?=(\d\d\d))/g;
print "@yeslap\n";

'?=' is a zero-width positive look-ahead assertion. In this case it 
matches three successive \d without the regex engine moving ahead.
When it sees the /g it bumps ahead one position. Is this what you need?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to