I'm trying to get grouped matches from the following URI:
route: "/user/{user}/{action}"
input: "/user/someone/news"
What's the appropriate regex for this? I've been searching myself sour for the past couple of hours...
I've tried something like this, but no result :(
~\/app\/user\/(?P<user>[.*]+)\/(?P<action>[.*]+)~
I get the groups back in the matches array, but no results based on the input inside the groups.
Desired output:
Array
(
[0] => Array
(
[0] => "someone"
)
[user] => Array
(
[0] => "someone"
)
[1] => Array
(
[0] => "news"
)
[action] => Array
(
[0] => "news"
)
)
To clarify with an example:
My controller has the following route: /app/user/{username}/{action}
The request URI from the browser is: /app/user/john/news
How do I match that request URI against that route using a regex patter while catching the variables between the brackets?
/user/(?P<user>[^/]+)/(?P<action>[^/]+)
Just to explain a couple problems with your original regex:
[.*]+
means a positive number of occurrences of a dot and an asterisk only, example: *.*.*
or .
or ......
; [^/]+
describes a positive number of any characters but slashes.~
as delimiters.