title: regular expressions: match any file under a certain directory, UNLESS the leaf directory is called "script"
body: <p>I need a regular expression that will match on any file under <code>/path/foo</code>, unless the leaf directory is called <code>script</code>.  So, for example, these should match:</p>
  
  <pre><code>/path/foo/file.txt
  /path/foo/bar/baz/file.txt
  /path/foo/script/bar/file.txt &lt;-- not the leaf directory, so this is fine
  </code></pre>
  
  <p>But these should not:</p>
  
  <pre><code>/path/bar/file.txt
  /path/foo/bar/script/file.txt &lt;-- leaf directory, so no match
  /path/foo/script/file.txt
  </code></pre>
  
  <p>I've tried a couple things, but they all have slight issues:</p>
  
  <ol>
  <li><code>/path/foo/(?!.*script)/[^/]*</code> matches if the leaf directory CONTAINS the string "script"</li>
  <li><code>/path/foo(?!.*/script)/[^/]*</code> matches paths like <code>/path/foo1/script/file.txt</code></li>
  <li><code>/path/foo/(?!.*/script)/[^/]*</code> matches only when there is a layer between <code>foo</code> and <code>script</code>, or if there are 2 slashes after <code>foo</code> for some reason</li>
  </ol>
  
  <p>I can't quite get it right.  Basically, I need to put any number of <code>/[^/]+</code> after <code>foo</code>, then I can use <code>(?!/script)</code> as the negative lookahead.  How do I write that regular expression?</p>