title: Regex for matching a string that can end with a character or not
body: <p>I have this regex</p>
  
  <pre><code>^([^&gt;]+)/([^&gt;]+)/([^&gt;]+)/([^&gt;]+)/([^&gt;]+)/$
  </code></pre>
  
  <p>It matches a generic url, like</p>
  
  <pre><code>www.site.com/complete/path/for/this/page/
  </code></pre>
  
  <p>The problem is that if i go to</p>
  
  <pre><code>www.site.com/complete/path/for/this/page
  </code></pre>
  
  <p>I get a 404 error, because my regex matches that string only if it ends with a slash.</p>
  
  <p>How can i tell the regex to match the string whether it ends with a slash or not?</p>
  
  <p>I thought about duplicating my rules to match the two cases but i think it is a very ugly way to do it, i'm sure that there is a better way to do it.</p>