Regex for Browser Versions

From: Date: Thu, 05 Jun 2003 18:00:23 +0000
Subject: Regex for Browser Versions
Groups: php.general 
Request: Send a blank email to php-general+get-150384@lists.php.net to get a copy of this message
Im trying to pull the Mozilla version and *possibly* the MSIE x.xx string out $_SERVER['HTTP_USER_AGENT'] If I did this correctly, (MSIE\s\d\.\d{1,2})? should mean that if its there pull it out, else move on, since its not there. When viewing this script via a windows browser, it doesn't match the MSIE section. If I take out the trailing ?, it will match successfully. But when viewing it with a mozilla browser, the regex fails as there is not MSIE string in there. Any help with this would be appreciated. Thanks <?php var_dump($_SERVER['HTTP_USER_AGENT']); echo '<p>'; preg_match('/^(Mozilla\/\d\.\d{1,2}|Opera\/\d\.\d{1,2})\s\(.*?(MSIE\s\d\.\d{1,2})?.*?\)(\sOpera)?/', $_SERVER['HTTP_USER_AGENT'], $foo); var_dump($foo); ?>

« previous php.general (#150384) next »