I have URI route like:
/dir/:dir1/:val1-:val2
I need a regular expression to:
- Know if the route match the real URI (es. /category/cars/ferrari-10)
-
Get parameters and values like the follow:
dir1 => cars
val1 => ferrari
val2 => 10
How to do this job?
THank you!
Using regex named groups and
preg-match:The above will result in the following array:
Also, if you want to remove the unnamed groups, you can use the following:
References:
preg-match