For practice i'm creating my own PHP router. This router could take in parameters which are specified like this:
{i:variableName}
The i
stands for the parameter type (in this case integer) and the variableName
stands for the variablename.
A single routing URI could look like this:
/home/{i:id}-{s:noVar}/{m:varName}/{s:someOther}
I've created the following regex pattern for this purpose:
[^{}]*({((?<type>\D):)?(?<name>[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]+)})[^{}]*
For not having 2 parameters next to each other, and having a character next to it, I expanded the regex with this piece:
[^{}]*
An example for this is that I won't be able to do stuff like:
/home/{i:id}{s:noVar}/{m:varName}{s:someOther}
There need to be characters between them.
I thought this piece of regex would do, "Do not include zero or more of the {
or }
character.
When I run this regex on a pattern like /home/{i:id}{s:noVar}/{m:varName}/{s:someOther}
, it still retrieves all the parameters, even the ones that are next to each other.
How is this possible and how can I make it so that the regex will only retrieve parameters that aren't next to each other?