title: Backbone.js Router Matching Optional Parameters
body: <p>I'm trying to create a backbone router that can match optional parameters.</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>routes: {  
    '/jobs'                                     : 'jobs',
    '/jobs/p:page'                              : 'jobs',
    '/jobs/job/:job_id'                         : 'jobs',
    '/jobs/p:page/job/:job_id'                  : 'jobs'
  }
  
  jobs: function(page, job_id){
     // do stuff here ....
  }
  </code></pre>
  
  <p>If I navigate to URL abc.com/<strong>#/jobs/p104/</strong> the <strong>page</strong> parameter will be <strong>104</strong>.  However, if navigate to abc.com/<strong>#/jobs/job/93</strong>, the <strong>job_id</strong> parameter is <strong>undefined</strong> but the <strong>page</strong> parameter is <strong>93</strong>.</p>
  
  <p>So Backbone's router basically matches the routes hash parameters by order and not by name.</p>
  
  <p>I know the solution would be to use a *splat and split the parameters with regex, but I can't seem to get the regex part to work (my regex is pretty rusty).  Can someone please help?</p>
  
  <p>If there's a better solution than using *splat, can someone please share?</p>