If I've understood the rules, I *think* this would do the job, but it is a compicated thing to generate testcases for. Do you have any?

#! perl -slw use strict; my $polar = 'DEHAW'; # Uniq E my $charged = 'DGYAH'; # Uniq Y my $hydphb = 'GAFIVL'; # Uniq FIVL my $re_seq = qr[ # Capture ( # start char [$polar$charged] # Must contain motif (?= .* H[$hydphb][$polar][$hydphb]W .* ) # Mustn't contain more than 4 polar chars (?! (?: .* [$polar] ){5} ) # 18-24 polar|hydphb chars # Excludes the start and end chars (Adjust if wrong!) [$polar$hydphb]{18,24} # # end char [$polar$charged] ) ]x; while( <DATA> ) { chomp; print "\nTesting '$_'"; s[\s+#.*$][]; print "matched: '$1'" while m[$re_seq]g; } __DATA__ YVVVVVVVVVVHVEVWVVY # 1 too short YVVVVVVVVVVHVEVWVVVY # min match YVVVVVVVVVVHVEVWVVVVVVVVVY # max match YVVVVVVVVVVHVEVWVVVVVVVVVVY # 1 too long YVVVVVVVVVVHVEVWVVVVVVVVEY # max polar YVVVVVVVVVVHVEVWVVVVVVVEEY # too many polar YVVVVVVVVVVHVYVWVVVY # missing motif

Results

P:\test>junk Testing 'YVVVVVVVVVVHVEVWVVY # 1 too short' Testing 'YVVVVVVVVVVHVEVWVVVY # min match' matched: 'YVVVVVVVVVVHVEVWVVVY' Testing 'YVVVVVVVVVVHVEVWVVVVVVVVVY # max match' matched: 'YVVVVVVVVVVHVEVWVVVVVVVVVY' Testing 'YVVVVVVVVVVHVEVWVVVVVVVVVVY # 1 too long' Testing 'YVVVVVVVVVVHVEVWVVVVVVVVEY # max polar' matched: 'YVVVVVVVVVVHVEVWVVVVVVVVEY' Testing 'YVVVVVVVVVVHVEVWVVVVVVVEEY # too many pol +ar' Testing 'YVVVVVVVVVVHVYVWVVVY # missing moti +f'

I make no predictions about efficiency:)


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail


In reply to Re: Searching for character classes of various quantities AND a motif by BrowserUk
in thread Searching for character classes of various quantities AND a motif by seaver

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.