// A simple way to check for HTML strings or ID strings
// (Both of which we optimize)
QuickExpr =/^ (? : [^ <] * (<[\ W \ W] +>) [^>] * $ | # ([\ w \-] +) $ )/
According to jquery's annotation, it matches the HTML string and ID selector.
When I first looked at this regular expression, how do I match zero or more non-<and match <? Is it true or not? Besides, shouldn't html tags be directly matched?
First (? : Pattern) matches pattern but does not get the matching result. That is to say, this is a non-get match and is not stored for future use. And it will match all the content not in parentheses.
The following is an example.
Copy codeThe Code is as follows:
Var quickExpr =/^ (? : [^ <] * (<[\ W \ W] +>) [^>] * $ | # ([\ w \-] +) $ )/;
Sss = "jytjt <dd1> </1> fefef"
Matchw.quickexpr.exe c (sss );
Alert (match );
The result is jytjt <dd1> </1> fefef =, <dd1> </1>
We can see that exec returns an array, and the second string is? : Match <> non-External <and non-> characters
The method for obtaining results in jquery is also match [1]. Therefore, even if you input extra html tags to the jquery selector, it can filter out the correct html tags. And here? : # Is filtered out, so only the id with no # is obtained.
Therefore, this jquery regular expression means to filter html tags or id delimiters.