Is it possible to do a preg_match() on something that shouldn’t be a match whilst still returning true?
For example, at the moment we have…
if (preg_match('#^Mozilla(.*)#', $agent)) {
We want to check if the Mozilla string is not in $agent, but still have preg_match return true.
We can’t change it to:
if (!preg_match('#^Mozilla(.*)#', $agent)) {
What you want is a negative lookahead, and the syntax is:
Actually, you can probably get away with just
#^(?!Mozilla)#for this. I don’t know how PHP will feel about a pattern that’s nothing but zero-width tokens, but I’ve tested it in JavaScript and it works fine.Edit:
If you want to make sure
Mozilladoesn’t appear anywhere in the string, you could use this……but only if you can’t use this!