title: Optional path variables in Spring-MVC RequestMapping URITemplate
body: <p>I have the following mapping:</p>
  
  <pre><code>@RequestMapping(value = "/{first}/**/{last}", method = RequestMethod.GET)
  public String test(@PathVariable("first") String first,  @PathVariable("last")  
    String last) {}
  </code></pre>
  
  <p>Which for the following URIs:</p>
  
  <pre><code>foo/a/b/c/d/e/f/g/h/bar
  foo/a/bar
  foo/bar
  </code></pre>
  
  <p>maps <i>foo</i> to <i>first</i> and <i>bar</i> to <i>last</i> and works fine.</p>
  
  <p>What I would like is something that maps everything between foo and bar into a single path param, or null if there is no middle (as in the last URI example):</p>
  
  <pre><code>@RequestMapping(value = "/{first}/{middle:[some regex here?]}/{last}", 
    method = RequestMethod.GET)
  public String test(@PathVariable("first") String first, @PathVariable("middle")
    String middle, @PathVariable("last") String last) {}
  </code></pre>
  
  <p>Pretty stuck on the regex since I was hoping that something simple like {middle:.*}, which <em>only</em> maps to /foo/a/bar, or {middle:(.*/)*}, which seems to map to nothing.</p>
  
  <p>Does the AntPathStringMatcher tokenize upon "/" prior to applying regex patterns? (making patterns that cross a / impossible) or is there a solution?</p>
  
  <p>FYI this is in Spring 3.1M2</p>
  
  <p>This seem similar to <a href="https://stackoverflow.com/questions/5879666/requestmapping-controlers-and-dynamic-urls">@RequestMapping controllers and dynamic URLs</a> but I didn't see a solution there.</p>