I don’t know regular expressions so well, I have a doubt regarding the possibility to get partials variables from a regex check. I try to explain what I am looking for…
I have those kind of paths:
example.com/dir1/
example.com/dir1/val1
example.com/dir1/val1-val2
I would like to create an expression that extracts dir1 val1 and val2.
My questions is:
Can I extract only the variables that exists or do I have to write 3 expressions? I mean…
If I put a rule to use: example.com/dir1/val1-val2
Can I only get dir1 if I pass url like: www.example.com/category (dir1 = category) ?
then If the url was: www.example.com/category/car
get dir1 = category and val1 = car
explode("/", $url)is easiest if possible. If the structure is more complex than that allows for, you could use preg_split() instead and list all the possible characters that can be used as subdividers.