Kevin Montrose
Kevin Montrose

Reputation: 22581

Determine if a url matches a Route, and pull out the terms if it does

I've 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?

Upvotes: 1

Views: 659

Answers (3)

Scott
Scott

Reputation: 13931

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.

Upvotes: 2

Justin
Justin

Reputation: 4477

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

Upvotes: 0

Raj Kaimal
Raj Kaimal

Reputation: 8304

Would the Routing Debugger help? Comes with sample code too.

http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

Upvotes: 0

Related Questions