I'm trying to match different urls to MVC actions of my controller.
Here is the current expression i'm testing:
#^/products((/([0-9]+)-([0-9a-z\_]+))*(/(index\.(html|pdf|xml|json))?)?)?$#i
When i try to match this to:
/products/22-test/25-test2
I was expecting to get (via preg_match_all) the following results:
array(5) {
[0]=>
string(26) "/products/22-test/25-test2"
[1]=>
string(17) "/22-test"
[2]=>
string(2) "22"
[3]=>
string(5) "test"
[4]=>
string(17) "/25-test"
[5]=>
string(2) "25"
[6]=>
string(5) "test2"
}
But instead i get
array(5) {
[0]=>
string(26) "/products/22-test/25-test2"
[1]=>
string(17) "/22-test/25-test2"
[2]=>
string(9) "/25-test2"
[3]=>
string(2) "25"
[4]=>
string(5) "test2"
}
UPDATE
The problem is that i'm not getting the category list translated into individual elements just so that i make my problem as clear as possible...
I'm using (/([0-9]+)-([0-9a-z\_]+))* in an attempt to transform as many category identifiers into a parsed item. Thats why i used (...)*, it should allow any number of categories to be matches and should match each of them no?
UPDATE 2
It seems that if i update the regexp to support many times the same category identifier, it gets parsed, i was hoping that (...)* would parse it many times instead of giving me one big list of category identifiers.
For example, this works fine:
#^/products((/([0-9]+)-([0-9a-z\_]+))?(/([0-9]+)-([0-9a-z\_]+))?(/([0-9]+)-([0-9a-z\_]+))?(/([0-9]+)-([0-9a-z\_]+))?(/([0-9]+)-([0-9a-z\_]+))?(/(index\.(html|pdf|xml|json))?)?)?$#i
But forces me to repeat the category selector MANY times. So if i have a client that decides to put more than X categories in his catalog, i'm blocked and the urls won't resolve correctly...
Is there any way to support that?
#^/products((/([0-9]+)-([0-9a-z\_\-]+))*(/(index\.(html|pdf|xml|json))?)?)?$#iTry That