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?
This regex should work for you:
$pattern = '%^/admin(/[\w-]*)?$%'
This will match any of:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With