Like so:my $Are = '^(.*)' . join('(.*)', @A) . '(.*)$';
my $Are = join '(.*)', '^', @A, '$';
I'd also use a nongreedy .*? there instead.
You provided a code base I liked quite a bit and couldn't stop tinkering with though - that temporary @A was annoying. :) Eventually it occured to me I could just capture the matches from $A as well:
Now it all goes in a single array where every odd element is guaranteed to be one character long, while every even element may have any length incl zero. With that in mind, I wrote a cleanup loop and eventually arrived at this:my $Are = join '(.*?)', '^', (map "($_)", $A =~ /(.)/sg), '$';
#!/usr/bin/perl -w use strict; my $A = 'ATGGAGTCGACGAATTTGAAGAAT'; my $B = 'xxxxxxATGGAGyxxxTCGAzxxxxCGAATTTGAAxxwGAAT'; my $Are = join '(.*?)', '^', (map "($_)", $A =~ /(.)/sg), '$'; (my @introns = $B =~ m/$Are/) or die "There was no possible way to match the input."; my @seq; while(@introns) { my $match = shift @introns; if(@seq and not $match) { $seq[-1] .= shift @introns || ''; next; } push @seq, $match; } print "$A\n@seq\n"; __END__ ATGGAGTCGACGAATTTGAAGAAT xxxxxx ATGGAG yxxx TCGA zxxxx CGAATTTGAA xxw GAAT
Update: hrm.. it doesn't work so well anymore once you substitute "real" sequences for the dummy characters in $B..
ATGGAGTCGACGAATTTGAAGAAT
ATGGAG A T GGAGT CGA T CGAA G T CACCGAA TT T GAA TTT GAAT
I suspect nearly the same is true for theorbtwo's code due to the nature of pattern matching.
Makeshifts last the longest.
In reply to Re^2: Complicated pattern match
by Aristotle
in thread Complicated pattern match
by dr_jgbn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |