if (!$is.IE5) {
开发者_如何学Python v = (ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])[1];
}
What does [1] mean in this reg expression??
It is an array deference on the answer.
v = (ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])[1];
The deference [1]
is applied to the function result, to get the first matched group (groups are delimited with parentheses ()
).
So v
= the first group match of (ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])
.
Note the ||[]
at the end which allows for no matches to not give an error.
This first group match is the ([\\d.]+)
group, the first parentheses is not stored due to the (?:...)
non-matching group construct.
精彩评论