hi again, amit --
In a message dated 3/2/2007 7:27:39 P.M. Eastern Standard Time,
[EMAIL PROTECTED] writes:
> hi amit --
>
> In a message dated 3/2/2007 4:54:57 P.M. Eastern Standard Time,
[EMAIL PROTECTED] (mailto:[EMAIL PROTECTED]) writes:
>
> > hello,
> > Thanks for your previous reponses.
> > Now this time i am using the right syntax for matching, for the string
like:
> >
> >
> > $temp= "XXXXAAAZZZZBBBSSSSCCCGGGGBBBVVVVVBBB"
> >
> > I need to write a regex for filterin out the string between.
> >
> > AAA
> > BBB
> > CCC
> >
> > so in the above case i should have the output as:
> >
> >
> > AAAZZZZZBBB
> > BBBSSSSSSCCC
> > CCCGGGGBBB
> > BBBVVVVVBBB
> > meaning all combinations of start and end for AAA BBB CCC.
> >
> > I have the regex for one of them but how do i do it simultaneously for
> > all 3 of them.
> >
> >
> > $temp='XXXXAAAZZZZBBBSSSSCCCGGGGBBBVVVVVBBB';
> >
> > @t = ($temp =~/(AAA)(.*?)(BBB)/g);
> > foreach (@t)
> > {
> >
> > print $_;
> >
> > }
> >
> > Am not able to figure out how will go about when just after the match
> > i need to match for
> > BBBSSSSCCC.
> >
> > Any suggestions
> >
> >
> > Thanks
>
>
> try this:
>
> C:[EMAIL PROTECTED]>perl -we "use strict; my $dna=
'XXXXAAAZZZZBBBSSSSCCCGGGGBBBVVVVVBBBAAA';
> my $starter = qr(AAA | BBB | CCC)x; my $stopper = qr(AAA | BBB | CCC)x;
my @seq;
> while ($dna =~ / ($starter) (.*?) ($stopper) /gx) { push @seq, qq($1$2$3);
pos($dna) = $-[3]; };
> print qq({$_} \n) for @seq"
> {AAAZZZZBBB}
> {BBBSSSSCCC}
> {CCCGGGGBBB}
> {BBBVVVVVBBB}
> {BBBAAA}
>
> the trick is resetting the search position in the body of the while loop.
as far as i know, there is
> no way to do this purely from within a regex.
> i defined two separate patterns for starting and stopping a subsequence
even though the actual
> groups are identical; it may serve if the groups ever differ.
> note that the above also captures the ``empty'' test case i added at the
end. if you do not want this,
> try this instead (the (.*?) becomes (.+?)):
>
> C:[EMAIL PROTECTED]>perl -we "use strict; my $dna=
'XXXXAAAZZZZBBBSSSSCCCGGGGBBBVVVVVBBBAAA';
> my $starter = qr(AAA | BBB | CCC)x; my $stopper = qr(AAA | BBB | CCC)x;
my @seq;
> while ($dna =~ / ($starter) (.+?) ($stopper) /gx) { push @seq, qq($1$2$3);
pos($dna) = $-[3]; };
> print qq({$_} \n) for @seq"
> {AAAZZZZBBB}
> {BBBSSSSCCC}
> {CCCGGGGBBB}
> {BBBVVVVVBBB}
>
>
> hth -- bill walters
>
i took another look at my original post and came up with a version that's
slightly more concise:
C:[EMAIL PROTECTED]>perl -we "use strict; my $dna=
'XXXXAAAZZZZBBBSSSSCCCGGGGBBBVVVVVBBBAAA';
my $starter = qr(AAA | BBB | CCC)x; my $stopper = qr(AAA | BBB | CCC)x; my
@seq;
while ($dna =~ / ($starter .*? ($stopper)) /gx) { push @seq, $1; pos($dna)
= $-[2]; }
print qq({$_} \n) for @seq"
{AAAZZZZBBB}
{BBBSSSSCCC}
{CCCGGGGBBB}
{BBBVVVVVBBB}
{BBBAAA}
br -- bill
<BR><BR><BR>**************************************<BR> AOL now offers free
email to everyone. Find out more about what's free from AOL at
http://www.aol.com.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs