(MSIE|(?!Gecko.+)Firefox|(?!AppleWebKit.+Chrome.+)Safari|(?!AppleWebKit.+)Chrome|AppleWebKit(?!.+Chrome|.+Safari)|Gecko(?!.+Firefox))(?: |\/)([\d\.apre]+)
This regular expression is capable of retrieving the browser and version for the following browsers;
- Internet Explorer
- Firefox (INCLUDING alpha and "pre" versions)
- Other browsers reporting a "Gecko" version in their user agent
- Chrome
- Safari
- Other browsers reporting an "AppleWebKit" version in their user agent
Returns the following strings;
- Browser Name (
"Safari"
,"Chrome"
,"Firefox"
, etc.) - Browser Version* (
"26.0.1410.64"
)
It gracefully handles browsers with confusing user-agents (for example Chrome, which reports Chrome, Safari and AppleWebKit in one go) for supported combinations.
* Note that the "Browser Version" returned on Safari is currently the WebKit version, not the Browser version.
Thank you, this is great - except, it doesn't handle IE Edge or 11. Try "(MSIE|Trident|(?!Gecko.+)Firefox|(?!AppleWebKit.+Chrome.+)Safari(?!.+Edge)|(?!AppleWebKit.+)Chrome(?!.+Edge)|(?!AppleWebKit.+Chrome.+Safari.+)Edge|AppleWebKit(?!.+Chrome|.+Safari)|Gecko(?!.+Firefox))(?: |\/)([\d\.apre]+)".