If I have an iOS user-agent like
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
or
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Mobile/7D11
How would I detect the iOS version using regular expressions so that it would return e.g.
4.0
for the above user agent?
Best Answer
The RegEx that is working for me is:
An iPad 5.1.1 has an
HTTP_USER_AGENT
like this:So 3 numbers in the iOS version and not iPhone OS present.
A possible Ruby implementation could be:
It returns nil if not iOS version found