JQuery_2.1.0_日记 5.4 Sizzle选择器(二)

时间:2022-12-18 17:20:43
(1)
whitespace = "[\\x20\\t\\r\\n\\f]";
匹配css3中空白符.
\x20:空格;\t水平制表符(tab);\r\n回车换行\f换页符

(2)
characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+"
匹配\后任意字符,字母或数字或-,ascii值非\00-\xa0范围内的字符

(3)
identifier = characterEncoding.replace( "w" , "w#" )
匹配\后任意字符,字母或数字或#或-,ascii值非\00-\xa0范围内的字符

(4)
attributes = "\\[" + whitespace + "*(" + characterEncoding + ")" + whitespace +
               "*(?:([*^$|!~]?=)" + whitespace + "*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|(" + identifier + ")|)|)" + whitespace + "*\\]"
   匹配属性选择器,例如:[arr^='val']
   捕获组1:characterEncoding :匹配例子中arr
   捕获组2:([*^$|!~]?=):匹配例子中^=
   捕获组3:['\"]:匹配例子中'
   捕获组4:(?:\\\\.|[^\\\\])*? 解释一下这个外层捕获\和后面的任意数量字符或非\字符,内层有?:是不捕获的,匹配例子中的val
   捕获组5:匹配identifier,匹配[id=#a]的情况
(5)
pseudos = ":(" + characterEncoding + ")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|" + attributes.replace( 3, 8 ) + ")*)|.*)\\)|)"
   匹配伪类表达式,例如li:nth-child(2n+1)
   捕获组1:characterEncoding :匹配例子中nth-child
   捕获组2:匹配例子中的2n+1
   捕获组3:匹配' or "
   捕获组4:匹配\和后面任何字符或非\字符
   捕获组5:匹配不再' or "内的\和后面任意字符或非\()[]字符或attributes

(6)
rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" )
   捕获 > + ~ 关系符
(7)
rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]" , "g" )
    匹配=[非'非"]