Consider this,
$uri = '/post/search/foo';
$pattern = '~/post/search/[A-Za-z0-9_-]+(?=/|$)~i';
$matches = array();
preg_match($pattern, $uri, $matches);
print_r($matches); // Success
It works fine, since [A-Za-z0-9_-]
belongs to foo
. Since I'm writing a route plugin,
I want this to be abble to match special chars as well.
I imagine a regex pattern to be like this:
[A-Z0-9!@#$%^&*()_+|\/?><~"№;:'*]+(?=/|$)
I've tried to escape each special character with a slash, and escape a whole pattern using preg_quote()
with no luck - I always encounter compilation failures.
The question is, how a proper matching for A-Z0-9!@#$%^&*()_+|\/?><~"№;:'*
should be done?