To insert a literal string into a pattern you can use \Q and \E. This insures that any characters that have special meaning in a regex will be escaped and treated as literals.
As for finding all overlapping patterns, see the documentation of pos and the 0 length lookahead operator in perlre. Using pos, 0 length lookahead regexes (look for (?=) might be preferable since the documentation says that (?{...}) is experimental.
use strict; use warnings; my $sequence = "GGGGGGGAGAAAAAAAAAAAAAAAGAAGGA"; sub tryPattern { my $pattern = shift; my $iCount = 0; while ($sequence =~ /(?=\Q$pattern\E)/g) { $iCount++; my $iPos = pos($sequence); my $sMatch = substr($sequence, $iPos, 5); print "$iPos: $sMatch\n"; pos($sequence) = $iPos + 1; } print "total found: $iCount\n"; } tryPattern($_) foreach qw(AAAAA GGGGG GGAGA GAAGG);
Best, beth
In reply to Re: Regex KungFu help needed
by ELISHEVA
in thread Regex KungFu help needed
by drblove27
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |