Hi.
I'm tryingo to build a regular expression that takes part of a URI that could vary in function of where the customer is, for instance:
I'd like to get products.
http://xxxxxxx.com/products/furnitures
I'd like to get products/funitures
http://xxxxxxx.com/products/furnitures/tables.
I'd like to get products/furnitures/tables but nothing beyond this, I mean if I've
http://xxxxxxx.com/products/furnitures/tables/night_table.html
I'd like to get /products/furnitures/tables
But I don't know how to get it... I've build one, but get all the stuff from /product... including all the parts of the URI
And since the application has several thousands of products, I'm getting a lot of values that i don't want. Anyone knows how to build it?
Thanks in advance and best regards
JMI
Answer by Jose I. ·
sorry... I've explained it wrong... what i need to exclude is more than third category, the final part of the URI is excluded with the regex that I've build... I mean:
http://xxxxxxx.com/products/furnitures/tables/night_tables/special/night_table.html
I'd like to get /products/furnitures/tables and nothing else.
Thanks in advance and best regards
JMI
Oh wait, I re-read your original post. here's the edited version:
(/[^/]+/?[^/]+/?[^/]+) |
---|
Edit: the limitation here is that the first URI part needs to be at least <regex> /... </regex> in order to match. If you also need to match the case where the URI is simply "/" then the following should be used:
(\A/\Z|/[^/]+/?[^/]+/?[^/]+) |
---|
This one doesn't work for:
www.test.com/product/details.html
www.test.com/product/cat2/details.html
I think it should be:
com/([^/]+/?[^/]+/?[^/]+)/
Just so he doesn't get the host part and also excludes any last element that does not end with "/" such as .html, etc
Just be mindful that the request
www.test.com/product
Won't match because there is no "/" at the end, not sure if we can have the best of both worlds, getting requests that don't end with a "/" and also not capturing the part of the request that ends with ".*"
JANUARY 15, 3:00 PM GMT / 10:00 AM ET