title: Regex for alphanumeric string with a maximum number of spaces
body: <p>I need a JS regex to match a string based only on a known first and last sub-string and number of spaces - and I don't care about the length or the nature of what is between the first and last sub-strings (other than the exact number of spaces).  </p>
  
  <p>The following is a possible start string (from which I get the first and last sub-strings and the number of spaces):</p>
  
  <p><code>cat apple dog mouse</code></p>
  
  <p>From this, I now know the string starts with <code>cat</code>, ends with <code>mouse</code> and contains exactly 3 spaces (they could be be anywhere between the ends, but they will not be consecutive).</p>
  
  <p>The string I need to match against might be:</p>
  
  <p><code>catfish mouse mouse dormouse mouse mouse</code></p>
  
  <p>or <code>cat mouse mouse mouse mouse mouse</code></p>
  
  <p>So, what I need to match would be, in the first case <code>catfish mouse mouse dormouse</code>, and in the second case <code>cat mouse mouse mouse</code> - in both cases a string starting with <code>cat</code>, ending with <code>mouse</code> and containing exactly 3 spaces.  At the moment, all my attempts match the entire sample string above, not just from <code>cat</code> to the third <code>mouse</code>.  Here is my latest failure:</p>
  
  <p><code>cat(?:(?![\s]{4,}).*)mouse</code></p>
  
  <p>I have a strong suspicion I'm overthinking this - but thanks for any suggestions.</p>