Question: I want to find out if user has used the words `admin` or `username` anywhere in their possible username string.

So if user wants to use `admin`, or `I am admin`, or `my admin name` or `my username`, as their username, I want my regexp to detect it. If he uses `adminmember` I can live with that, don't detect it. I also want detection to be case insensitive.

So far I got this, but it is not really working as I thought, since it will detect words that it shouldn't:

`/^[admin|username]+$/i`

This will match even `adm`, and it shouldn't. I have tried with word boundaries, but I couldn't make it work either, maybe I did something wrong. As you can see in my question I would like to detect word admin anywhere in the string, but if it is a part of some word I can skip it.

Thanks in advance.

Answer: 
Square brackets in a regexp are not for grouping, they're for specifying character classes; grouping is done with parentheses. You don't want to anchor the regexp with `^` and `$`, because that will only match at the beginning and end of the string; you want to use `\b` to match word boundaries.

```
/\b(admin|username)\b/i

```
Try the below snippet to keep your list of words in `Array`.

```
$input = "im username ";
$spam_words = array("admin", "username");
$expression = '/\b(?:' . implode($spam_words, "|") . ')\b/i';

if (preg_match($expression, $input)) {
  die("Username contains invalid value");
}
else {
  echo "Congrats! is valid input";
}

```

Working Fiddle URL:  

<http://sandbox.onlinephpfunctions.com/code/6f8e806683c45249338090b49ae9cd001851af49>