regex - Javascript Reg Exp number in brackets -
if (!$is.ie5) { v = (ua.tolowercase().match(new regexp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])[1]; } what [1] mean in reg expression??
it array deference on answer.
v = (ua.tolowercase().match(new regexp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])[1]; the deference [1] applied function result, first matched group (groups delimited parentheses ()).
so v = first group match of (ua.tolowercase().match(new regexp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[]).
note ||[] @ end allows no matches not give error.
this first group match ([\\d.]+) group, first parentheses not stored due (?:...) non-matching group construct.
Comments
Post a Comment