标签:
sizzle对于分组过滤处理都用正则,其中都有一个特点,就是都是元字符^开头,限制匹配的初始,所以tokenize也是从左边开始一层一层的剥离。
•可能会应用到正则如下:
// 空白 var whitespace = "[\\x20\\t\\r\\n\\f]"; // 匹配\后任意字符,字母或数字或-,ascii值非\x00-\xa0范围内的字符 var characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+" var identifier = characterEncoding.replace( "w" , "w#" ) // 匹配关系符> + ~ var rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ) // 匹配=[非‘非"] var rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]‘\"]*?)" + whitespace + "*\\]" , "g" )
•正则组合:
///^#((?:\\.|[\w-] | [^\x00-\xa0] ) +)/var ID = new RegExp("^#(" + characterEncoding + ")")
匹配ID,例如:$(‘#id‘)
var TAG = new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" );
匹配标签,例如:$(‘input‘)
var Class = new RegExp( "^\\.(" + characterEncoding + ")" );
匹配class名,例如:$(‘.test‘)
attributes = "\\[" + whitespace + "*(" + characterEncoding + ")" + whitespace + "*(?:([*^$|!~]?=)" + whitespace + "*(?:([‘\"])((?:\\\\.|[^\\\\])*?)\\3|(" + identifier + ")|)|)" + whitespace + "*\\]"
pseudos = ":(" + characterEncoding + ")(?:\\((([‘\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|" + attributes.replace( 3, 8 ) + ")*)|.*)\\)|)"
标签:
原文地址:http://www.cnblogs.com/huair_12/p/4181973.html