title: Regex in Route attribute - RESTful API ASP.NET Web API
body: <p>I've got a problem with regular expressions in Route attribute. I'd like to create RESTful API, where you can specify start date and end date in URL to filter results. What I've done till now is:</p>
  
  <pre><code>    [HttpGet]
      [Route("date/{startDate:datetime:regex(\\d{4}-\\d{2}-\\d{2})}/{*endDate:datetime:regex(\\d{4}-\\d{2}-\\d{2})}")]
      [Route("date/{startDate:datetime:regex(\\d{4}/\\d{2}/\\d{2})}/{*endDate:datetime:regex(\\d{4}/\\d{2}/\\d{2})}")]
      public IEnumerable&lt;Recommendation&gt; GetRecommendationByDate(DateTime startDate, DateTime? endDate) 
      {
          var output = db.Recommendations
              .Where(r =&gt; r.IsPublished == true &amp;&amp;
                          r.CreatedDate.CompareTo(startDate) &gt; 0 &amp;&amp;
                          r.CreatedDate.CompareTo(endDate.HasValue ? endDate.Value : DateTime.Now) &lt; 0)
              .OrderByDescending(r =&gt; r.LastModified)
              .ToList();
  
          return output;
      }
  </code></pre>
  
  <p>It doesn't work how I want, because second param should be nullable. When I pass only start date, I'm getting 404. Also format with slash doesn't work at all. What am I doing wrong? I thought * means that parameter is nullable...</p>
  
  <p>===EDIT===</p>
  
  <p>My URLs to match are both:</p>
  
  <p>https:// localhost:post/api/recommendations/date/10/07/2013/1/08/2014 - doesn't work</p>
  
  <p>https:// localhost:post/api/recommendations/date/10-07-2013/1-08-2014 - works</p>
  
  <p>and with nullable second parameter:</p>
  
  <p>https:// localhost:post/api/recommendations/date/10/07/2013 - doesn't work</p>
  
  <p>https:// localhost:post/api/recommendations/date/10-07-2013 - doesn't work</p>