in reply to Complicated pattern match
In general, it seems like you want to take the sequence of charaters in $A, make sure $B contains those characters, in that sequence, but with other stuff inbetween them. Then you want a list of the other stuff.
This should do it:
That should give you @introns as a list of everything that /didn't/ match. There will be zero-length strings for each position in which there was no junk, and otherwise the junk. Look at the output, and you'll see what I mean. Also, if there is more then one way of matching $B against $A, this will take each section of @introns to be as long as possible. If you'd prefer it as short as possible, that's easily possible. In either case, it will try it's hardest to get them to match. It will allow both leading and trailing junk, though your example only has trailing junk. These are left as exercises for the reader.#!/usr/bin/perl use warnings; use strict; my $A = 'ATGGAGTCGACGAATTTGAAGAAT'; my $B = 'xxxxxxATGGAGyxxxTCGAzxxxxCGAATTTGAAxxwGAAT'; my @A = split //, $A; my $Are = '^(.*)' . join('(.*)', @A) . '(.*)$'; my @introns = ($B =~ m/$Are/); if (!@introns) { die "There was no possible way to match the input."; } foreach (0..$#introns) { print "$_: $introns[$_] $A[$_]\n"; }
Update: Major revisions to code, changed caveats, tested.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Complicated pattern match
by Aristotle (Chancellor) on Jan 19, 2003 at 12:21 UTC |