title: PHP Regex Pattern - Match url if only one level deep
body: <p>My question is similar to this but I can't get it to work: <a href="https://stackoverflow.com/questions/4553686/path-regular-expression-allow-only-one-level">Path Regular Expression - Allow only one level</a></p>
  
  <p>I have an array with a bunch or urls from a website that are either a category or sub-category page so:</p>
  
  <pre><code>http://www.mysite.com/dogs/
  http://www.mysite.com/cats/
  http://www.mysite.com/food/
  </code></pre>
  
  <p>are category pages (only level beyond the root domain)</p>
  
  <p>Sub-category pages look like:</p>
  
  <pre><code>http://www.mysite.com/dogs/poodles/
  http://www.mysite.com/cats/siamese/
  http://www.mysite.com/food/pizza/
  </code></pre>
  
  <p>I want to strip out the sub-categories and only be left with category pages in the array.  Any url that contains anything beyond the first set of / / after the root url should be filtered out.</p>
  
  <p>I think I need to use preg_grep but using the pattern in the updated answer that I referenced above like</p>
  
  <pre><code>$regex = "#^/[^/]+/?$#";    
  $categories_only = preg_grep($regex,$array);
  </code></pre>
  
  <p>yields an empty array.</p>
  
  <p>What pattern will match this correctly?</p>