Per the following documentation: https://developers.google.com/chrome/mobile/docs/user-agent
Here is Chrome for iOS UA String:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3
And here is Safari for iOS UA String:
Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3
As best as I can tell the difference going forward will be that Chrome includes “CriOS”. I want to be able to distinguish between these two browsers and so set about doing that using a regular expression.
Using:
/Gecko\) (?!CriOS)/
I’m able to do that but am paranoid as I am not including iPhone in the expression (perhaps this will also trigger on Android, etc.)
I want to write the following regular expression that returns a match when:
- The string contains “iPhone”
- The string does not contain “CriOS”
How would I go about doing that?
FYI I’ve been using rubular for testing reg exp which has been awesome http://rubular.com/
This should do it :
iPhonematches any occurence of that word. It then uses a negative lookahead from theiPhonematch..*?CriOSmatches any/all characters until it findsCriOS. The(?!expr)is a negative lookahead. If the expression is false then what comes before it (Iphone) will match, otherwise it won’t.