title: How to find category-name, page number in http://domain.com/post-type/category/category-name/page/2
body: <p>I have an URL formatted like so:</p>
  
  <p><code>http://domain.com/post-type/category/category-name/page/2</code></p>
  
  <p>And need to extract only <code>category-name</code> no matter what follows.</p>
  
  <p>For example, in the url:</p>
  
  <p><code>http://domain.com/projects/category/print/page/2</code></p>
  
  <p>I only want the word</p>
  
  <p><code>print</code></p>
  
  <p>I am trying this regex: <code>category\/(.+)\/(?(?=(?:category)\/)^|(.+))\/(.+)\/?$</code> cobbled together via some searching, but I really am quite confused by Regex.</p>
  
  <p><a href="http://regex101.com/r/uG8pV8" rel="nofollow">http://regex101.com/r/uG8pV8</a></p>
  
  <p><strong>Note</strong></p>
  
  <p>I am executing this in PHP (in what I think is regex, correct?). At the moment, the Wordpress code is as so: <code>$newrules['projects/category/(.*/?)$'] = 'index.php?post_type=project&amp;project_cat=$matches[1]';</code> which seems to take the entire URL after <code>projects/category/</code></p>
  
  <p><strong>Edit</strong></p>
  
  <p>Is it also possible to get the page number as well?</p>
  
  <p>eg: <code>http://domain.com/post-type/category/category-name/page/2</code></p>
  
  <p>Is it possible to get only <code>category-name</code> and <code>2</code> as separate matches?</p>