i want match name of android device (e.g. "galaxy nexus") javascript regex pattern.
my user agent looks this:
"mozilla/5.0 (linux; u; android 4.0.2; en-us; galaxy nexus build/icl53f) applewebkit/534.30 (khtml, gecko) version/4.0 mobile safari/534.30"
if take between ";" , "build/" device name. has last occurence of ";" before "build/".
at moment have following expression:
var match = navigator.useragent.match(/;[\s\s]*build/)[0];
the problem is, expression takes between first semicolon , includes "build/". get:
"; u; android 4.0.2; en-us; galaxy nexus build"
does knows how can make expression smarter "galaxy nexus build"?
you can test :
var txt = "mozilla/5.0 (linux; u; android 4.0.2; en-us; galaxy nexus build/icl53f) applewebkit/534.30 (khtml, gecko) version/4.0 mobile safari/534.30"; var regex = /;\s*([^;]+)\s+build\//g; var match = regex.exec(txt)[1]; alert("#" + match + "#");
Comments
Post a Comment