3 ms·
Not quite what you asked for, but how about this? ~^(?| xx(x)/user/([^/]+)/(\d+) | x(xx)/user/(\d+) | (xxx)/user/([^/]+) )$~x Then just prep
by mzs 13y ago
Not quite what you asked for, but how about this?
~^(?|
xx(x)/user/([^/]+)/(\d+)
| x(xx)/user/(\d+)
| (xxx)/user/([^/]+)
)$~x
Then just prepend 'xxx' to the front of uri in the call to preg_match. Now the second entry in matches tells you which handler, so for example for uri = '/user/nikic/42' you pass 'xxx/user/nikic/42' and get back 'xxx/user/nikic/42', 'x', 'nikic', and '42' where that 'x' tells you it's the first handler.
I'm not an expert in how php does REs but I imagine there may be a way to use preg_replace or similar to replace the first '/' in the uri with 'x', 'xx', or 'xxx' and still get a the groups returned for the matches for user and id say. This could save a potentially costly string creation.