我有以下两个变量:
var firefox = "Mozilla/5.0 (Android; Mobile; rv:32.0) Gecko/32.0 Firefox/32.0"
var chrome = "Mozilla/5.0 (Linux; Android 4.4.4; Nexus 4 Build/KTU84Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.57 Mobile Safari/537.36"
我想从中抓住:
Nexus 4
Firefox|Chrome
所以正则表达式替换后的结果字符串应为:
Firefox 32.0
Nexus 4 Chrome 38.0.2125.57
到目前为止,我有一个正则表达式:
var newf = firefox.replace(/^.*(Nexus)?.*(Firefox|Chrome)\/([\d\.]*).*/, "$1 $2 $3")
var newc = chrome.replace(/^.*(Nexus)?.*(Firefox|Chrome)\/([\d\.]*).*/, "$1 $2 $3")