title: PCRE Regex Match /x... but not /y/x
body: <p>When configuring redirections, it's common to run into multiple pages that include some of the same path strings. We've ran into this instance multiple times where we need to redirect:</p>
  
  <pre><code>https://example.com/x...
  </code></pre>
  
  <p>But not:</p>
  
  <pre><code>https://example.com/y/x...
  </code></pre>
  
  <p>To match the /x... we use PCRE regex of:</p>
  
  <pre><code>/x.*
  </code></pre>
  
  <p>We've been struggling to get the exclude to match correctly; we apologize in advance as our regex is a bit weak, here's our pseudo code:</p>
  
  <pre><code>Match all /x... except /y/x...
  </code></pre>
  
  <p>Here is what we thought that looked like:</p>
  
  <pre><code>^\/(?!y\/).x.*
  </code></pre>
  
  <p>In our mind that reads:</p>
  
  <pre><code>Any query starting with /x..., except starting with /y/x...
  </code></pre>
  
  <p>Thank you in advance, and please feel free to suggest better formatting, we are not stack overflow pros.</p>