I'm wanting to preg_match the following URIs. Note usernames are: [\w]{1,15}
/username
/username/foo
/usersname/bar
I want these to fail
/username/anythingelse
The username is mandatory, so the preg_match should work if just a username is given, and then check if anything after is either foo
or bar
.
preg_match('{^\/([\w]+){1,15}/{/foo|/bar}?$}', $uriString)
You can probably tell my preg_match fails. How may I fix this?