0
votes

I'm looking for a regular expression to split and capture a url path eg with example.com/param1/param2/param3 I would like param1, param2 and param3 to be captured. There could be an unknown number of parameters. This will be used with PHP's preg_match. Can this be done?

EDIT: This will be used with PHP's preg_match, because I am using it as a Zend Router Rule. Can this be done?

2

2 Answers

3
votes

You don't need regex if it's always going to be a /, you could just explode it into an array:

$array = explode('/', $url);
0
votes

Depends on if it allows it

(/[^/]*)+

That'll give multiple matches /param1, /param2, /param3

Then just strip the slashes