Experiencing issues with regular expressions in JavaScript. Attempting to extract the version number and browser name, such as "Firefox 22.0" or "MSIE 8.0".
console.log(navigatorSaysWhat())
function navigatorSaysWhat()
{
var rexp = new RegExp(/(firefox|msie|chrome|safari)\s(\d+)(\.)(\d+)/i);
// works in ie but not in firefox
var userA = navigator.userAgent
var nav = userA.match(rexp);
return nav
}
The current expression is not quite achieving the desired result. The goal is to match the browser name and version number from the strings.
Examples of user agent strings: Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0 Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0;
Attempts have been made to adjust the expression, such as using (firefox|msie|chrome|safari)\s(\d+)(./\/)(\d+) to match the backslash, or (firefox|msie|chrome|safari)\s(\d+)(*)(\d+) for any character, but without success.