You used a condition (the first group starting with ?
) with wrong syntax, thats your Warning.
But I think you don't need a conditional regex, try
var_dump(preg_match("#^(?!(Bob|Alice)$).*#", 'John'));
I moved the Anchor ^
to the very start of the expression and $
outside the alternation, so it is valid for both alternatives.
This regex will match every string (without newline characters), that is not only "Bob" or "Alice".