[1]在这个reg表达式中意味着什么?
if (!$is.IE5) { v = (ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])[1]; }What does [1] mean in this reg expression??
最满意答案
答案是对数组的尊重 。
v = (ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])[1];将函数[1]应用于函数结果,得到第一个匹配的组(组用圆括号()分隔)。
所以v = (ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])的第一组匹配(ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[]) 。
请注意末尾的||[] ,它允许不匹配不会给出错误。
第一组匹配是([\\d.]+)组,由于(?:...)不匹配的组结构,第一个括号不会被存储。
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.
括号内的Javascript Reg Exp号码(Javascript Reg Exp number in brackets) if (!$is.IE5) { v = (ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])[1]; }[1]在这个reg表达式中意味着什么?
if (!$is.IE5) { v = (ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])[1]; }What does [1] mean in this reg expression??
最满意答案
答案是对数组的尊重 。
v = (ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])[1];将函数[1]应用于函数结果,得到第一个匹配的组(组用圆括号()分隔)。
所以v = (ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[])的第一组匹配(ua.toLowerCase().match(new RegExp(".+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)"))||[]) 。
请注意末尾的||[] ,它允许不匹配不会给出错误。
第一组匹配是([\\d.]+)组,由于(?:...)不匹配的组结构,第一个括号不会被存储。
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.
发布评论