title: Regex match required and optional parts of string
body: <p>I'd like to do a preg_match on a uri string with optional and required parts but I can't figure it out.</p>
  
  <p>Example to match:</p>
  
  <pre><code>/segment/(required)/segment(/optional)
  </code></pre>
  
  <p>I want both strings below to match against the above</p>
  
  <pre><code>/segment/required/segment/optional
  </code></pre>
  
  <p>and</p>
  
  <pre><code>/segment/reguired/segment
  </code></pre>
  
  <p>I know the policy is to not write for me but I can't figure this out so thought I'd at least ask.</p>