I would like to use regular expressions to identify a motif in an amino acid sequence. Part of the the motif is described as '2 or more out of XXXX are D or E'. I wonder if there is a way to specify this part directly with regular expressions instead of writing out all the alternatives or using a more iterative approach.

I'm actually using this in the find box of my editor (sublime text) as it accepts regex (not sure what extensions/definitions it goes to). Otherwise a perl version of regex is where I would implement this.

Thanks!

edit: changed title slightly

edit: changed question to include *or more*.
<p>I think I&#39;ve figured it out now, using lookahead <code>(?=pattern) </code>to link two regular expressions like an <code>AND</code>:</p>

<p><s><code>(?=.?[DE]{1,4}.?[DE]{1,2}.?).{4}</code></s></p>

<p>The first part (in brackets) stipulates the pattern described by the following part must have at least 2 Ds or Es which may have other characters before, after or between them. The second part (following brackets) says the result must be four characters long.</p>

<p>EDIT: PLUS an alternate with two wildcard characters in the middle</p>

<p><code>(?=.?[DE]{1,4}.?[DE]{1,2}.?|[DE]..[DE]).{4}</code></p>

<p>I&#39;m not sure how this would deal with overlapping motifs (I only came across regular expressions recently) but this is adequate for my needs now.</p>
