I'开发者_如何学Pythonve got a big old log file I'm trying to break down in terms of routes.
Essentially, I'm getting input of a path (/questions/31415
for example) and a list of all the registered Routes. What I want out is a Route
and the parameters specified in the route (so in, /questions/{id}/{answer}
I'd get id
and answers
out).
I've got a working solution that basically generates a nasty bit of regex on the fly with named groups to do matching and parsing all-in-one. My gut tells me this is a brittle way to do it, and frankly there has to be a better way, right?
I know this is an old question, but on the off chance someone else gets here via Google, I asked and answered my own question on this same subject here.
Would the Routing Debugger help? Comes with sample code too.
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
This is very similar to the PathParameterFilter often used with spring/REST. I don't have a link to the source any more, but it has the regular expressions you need to pull things out. http://www.carbonfive.com/community/archives/2007/06/parameterized_rest_urls_with_spring_mvc.html
精彩评论