in reply to Pattern searching allowing for mis-matches...
Something like this?
$seq = 'TGTGTGTGTGTG';; @tests = qw[ TX TXXX ];; for my $test ( @tests ) { ( my $re = $test ) =~ tr[X][.]; print "'$1'" while $seq =~ m[(?=($re))]g; };; 'TG' 'TG' 'TG' 'TG' 'TG' 'TG' 'TGTG' 'TGTG' 'TGTG' 'TGTG' 'TGTG'
Replacing your 'X's with '.'s gives you a wildcarding ability.
By placing the capture inside a lookahead, the matchpoint will only be advanced by one position after each match, rather than the length of the match. That allows overlapping matches to be found.
|
|---|