I'm trying to use the regex possibilities of Spring MVC's RequestMapping to distinguish between several REST APIs:
/somepath/{item:[^&?/]+}/{subitem:[^&?/]+}
/somepath/{item:[^&?/]+}
/somepath
In each case the API returns a totally different JSON object.
Spring MVC has the usually useful habit of conflating multiple slashes or ignoring trailing slashes. However, I need to get around that in this case. So I'm using regular expressions to handle the cases with the path variables are empty i.e. to stop /somepath//asubitem
being matched to the second API rather than the first.
The problem is that when I use a slash character in the regex, the pattern will not match. Just using [^&?]+
matches but obviously this is not quite what I need.
Does anyone have an idea why we have this regex behaviour and how to get around it?