I need to match Safari browsers, but not Chrome browsers using one Regex. I usually don't have a problem with regex, but negative look-aheads are stumping me here.
/(?!chrome)(safari)/i.test("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5");
Can't figure out why this is returning true
.
safari
which is not equal tochrome
. (Not very meaningful if I understand it correctly.)q(?!u)
matches aq
that is not followed by au
. That won't help here. You actually need a negative lookbehind for this job (string containsSafari
that is not preceded byChrome
) but JS does not support negative lookbehind.