Skip to content Skip to sidebar Skip to footer

Efficient User-agent Regex To Find Safari In Python

To find out if user-agent pertains to Safari, one must look for the presence of Safari but not the presence of Chrome. I am also assuming that this needs to be case-insensitive. I

Solution 1:

Since you're testing whether certain fixed strings appear in a given string, it's probably easiest and most efficient to forgo regexes entirely:

if 'safari' in userAgentString.lower() and 'chrome' not in userAgentString.lower():
    print "Found Safari"

Post a Comment for "Efficient User-agent Regex To Find Safari In Python"