jQuery中的quickExpr

jQuery 源码中的 quickExpr 是用来检测参数 selector 是否是复杂的 HTML 代码(如“abc<div>”)或 #id,匹配结果存放在数组 match 中

1 // A simple way to check for HTML strings or ID strings
2 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
3 quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/;

quickExpr = /^(?:pattern)/;

         pattern = p1|p2;

              p1 = [^#<]*(<[\w\W]+>)[^>]*$;

              p2 = #([\w\-]*)$;

1、(?:pattern):表示匹配 pattern 但是不记住匹配项

2、p1:匹配复杂的 HTML

3、p2:匹配 #id

var quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/;
ss="aa<dd>#dd</cc>ff";
match=quickExpr.exec(ss);

//["aa<dd>#dd</cc>ff", "<dd>#dd</cc>", undefined, index: 0, input: "aa<dd>#dd</cc>ff"]
console.log(match);
//['#target', undefined, 'target']
quickExpr.exec( '#target' );