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.

Replies are listed 'Best First'.
Re^3: Perl regular expression for amino acid sequence
by hv (Prior) on Dec 02, 2004 at 13:34 UTC

    This is a very nice solution, I haven't seen that trick before.

    Hugo