title: Matching an exact number of tokens in a regex
body: <p>I never worked deep with regex...</p>
  
  <p>I have this regex: <code>LAX-Application-CustomerDrives-&lt;environment&gt;-&lt;org&gt;-&lt;area&gt;-&lt;title&gt;</code></p>
  
  <p>The first 3 words including the dashes are always the same, the rest, varies only in that the environment particle could or could not be there.</p>
  
  <p>Now, I need to set the regex variable to <code>LAX-Application-CustomerDrives-&lt;env&gt;-&lt;org&gt;-&lt;area&gt;-&lt;title&gt;</code> if the environment is there, or else set the regex variable to <code>LAX-Application-CustomerDrives-&lt;org&gt;-&lt;area&gt;-&lt;title&gt;</code> if is not.</p>
  
  <p>In other words, I need 4 word-dash token (<code>UAT-&lt;org&gt;-&lt;area&gt;-&lt;title&gt;</code>) in the first case, and 3 (<code>&lt;org&gt;-&lt;area&gt;-&lt;title&gt;</code>) in the other.</p>
  
  <p>I have this regex in the first case: <code>LAX\-Application\-CustomerDrives\-([A-Z]+\-[A-Z]+\-[A-Z]+\-[A-Za-z]+)</code> which works for when there are 4 pairs (when environment is there) and doesn't match if there are only 3, but the regex: <code>LAX\-Application\-CustomerDrives\-([A-Z]+\-[A-Z]+\-[A-Za-z]+)</code> will match in any case.</p>
  
  <p>I need to explicitly match for 4 and only 4 pairs (<code>/[A-Z]\-/g</code>), if the environment variable is set, and 3 and only 3 pairs if is not set.</p>
  
  <p>I've tried with <code>LAX\-Application\-CustomerDrives\-([A-Z]+\-[A-Z]+\-[A-Za-z]+){3}</code> and <code>{4}</code> but it won't work.</p>
  
  <p>Any ideas?</p>