Raphael Gbologah Raphael Gbologah - 1 year ago 78
PHP Question

Php Regular Expression Complex Matching

I'm working on a php mvc routing system and i need my router to be able to get the various parts of the url and map it accordingly like in this example:

url = controller/method/parameters/another/something/page/7

should map to:

controller = controller, method = method, parameters = parameters/another/something, page = 7

currently am only able to match


with this regex:


which translates into this pattern:


I am using named captures to get the parts. i need help with the regex to use to get the result as stated above.

Answer Source

You need to allow /s in your parameter's character class.


Demo: https://regex101.com/r/nX7cZ8/1

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download