I’ve taken a regular expression from jQuery to detect if a browser’s engine is WebKit and gets it’s version number, it returns 3 values extracted from the userAgent string: webkit/….…, webkit and ….… [“….…” being the version number].
I would like the regular expression to return just 2 values: webkit and ….….
I’m rubbish at regular expressions, so please can you give an explanation of the expression with your answer.
The regular expression I’m currently working with and wish to improve is: ./(webkit)[\/]([\w.]+)/
From Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13 this regular expression would return: webkit/525.13,webkit,525.13. I would wish it only returned webkit,525.13.
I appreciate all your help, thanks in advance!
In regular expressions, the values you get returned are those in parentheses:
You can just make the groups non-matching by adding
?:at the start of it:Edit after re-reading your question.
The return from the regex will contain (as shown in my examples above) the entire matched string, then the matched groups. If you want just the matched groups, just slice off the first value: