http://qs321.pair.com?node_id=411588


in reply to Re: Perl regular expression for amino acid sequence
in thread Perl regular expression for amino acid sequence

Here's a pure regex solution that works:
use strict; use warnings; while(<DATA>) { print "$_---\n"; my $m; while (/([QGYN]{2} # First two characters of the desired class (?: # Followed by the complex expression... # Lookback at the previous two chars (?<=(.)(.)) # Check that the next char differs from at least one of th +em (?:(?!\2)|(?!\3)) [QGYN] # Then take another of the desired class ){1,4} # ...1 to 4 times )/gx) { $m = $1; printf "---> $m starting at %d\n", pos($_)-length($m); } print "=====\n"; } __DATA__ QYGNGNG GGGGGNYGNQYNNNQGYQ QGYNNN xxxxxxxGNNNxxxxxxxNNNGYGYxxxxxxxGYGYNNNxxxxxxxNNNGNNNxxxxxxx

Caution: Contents may have been coded under pressure.