I came here searching for an answer to sniffing for iOS 6 via the useragent and found a wonderful answer here: How to detect iOS 6 and all minor versions by user agent?
All regular expressions I've worked with previously have been pretty simple and I'm banging my head against a wall trying to get this one working properly. Unfortunately the PHP parser isn't giving me any errors!
I know for a fact I'm doing something wrong, since I'm getting a match for the code below while running firefox on my laptop.
I would appreciate if anyone could point me in the right direction here, I can't figure out what I'm doing wrong.
$subject = $_SERVER['HTTP_USER_AGENT'];
$pattern = '~^(?:(?:(?:Mozilla/\d.\d\s*()+|Mobile\s*Safari\s*\d+.\d+(.\d+)?\s*)(?:iPhone(?:\s+Simulator)?|iPad|iPod);\s*(?:U;\s*)?(?:[a-z]+(?:-[a-z]+)?;\s*)?CPU\s* (?:iPhone\s*)?(?:OS\s*\d+\d+(?:\d+)?\s*)?(?:like|comme)\s*Mac\s*O?S?\s*X(?:;\s*[a-z]+(?:-[a-z]+)?)?)\s*)?(?:AppleWebKit/\d+(?:.\d+(?:.\d+)?|\s*+)?\s*)?(?:(KHTML,\s*(?:like|comme)\s*Gecko\s*)\s*)?(?:Version/\d+.\d+(?:.\d+)?\s*)?(?:Mobile/\w+\s*)?(?:Safari/\d+.\d+(.\d+)?)?.*$~';
if (preg_match($pattern,$subject))
{
echo "match";
}