title: Capture string without conditional ending
body: <p>I'm trying to capture the middle part of a URL, that contains a conditional ending:</p>
  
  <p>A URL can be of two sorts:</p>
  
  <pre><code>/a/b/(part/needed)
  /a/b/(part/needed)/page/#
  </code></pre>
  
  <p>here's the regexp I use:</p>
  
  <pre><code>preg_match('@/a/b/(.*)(/page/\d)?@i', '/a/b/some/text/page/1', $matches);
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>0=&gt;"/a/b/some/text/page/1",
  1=&gt;"some/text/page/1"
  </code></pre>
  
  <p>It's ok but it includes the conditional ending which I don't want!</p>
  
  <p>Can someone tell me how to not include the conditional string ending in it
  but still match when the last segment is present or absent?</p>