regular expression matching /admin/something not administrator
php, regex
Solution
This regex should work for you:
$pattern = '%^/admin(/[\w-]*)?$%'
This will match any of:
- /admin
- /admin/
- /admin/foobar
Problem
Hi I want to match strings like `/admin/` or `/admin/something` or `/admin` but not `/administration` or `/administrator`. I wrote this regular expression: ``` $pattern = '%^/admin(/|/[a-zA-Z0-9_-]{1,})?$%' ``` and it works, but it is something ugly. I want to know can it be written more cleaner and understandable?