Reputation: 3530
I'd like to exclude word user
and gallery
using regular expression.
^/(?!user|gallery)([a-z0-9_-]{3,64})$
My regexp also excludes words like mygallery
(in which gallery
is a substring). I want to have mygallery
included.
Thanks a lot in advance.
Upvotes: 0
Views: 119
Reputation: 32730
Try this :
$str = "mygallery and gallery user and username";
echo preg_replace("/\bgallery\b|\buser\b/","",$str);
Output :
mygallery and and username
Upvotes: 2
Reputation: 336108
Your regex should already accept mygallery
, but it would reject username
. Add anchors to make sure it doesn't:
^/(?!user$|gallery$)([a-z0-9_-]{3,64})$
Upvotes: 2