// A simple way to check for HTML strings or ID strings
// (both of which we optimize for)
quickExpr = /^(?:[^<]*(< ;[wW] >)[^>]*$|#([w-] )$)/
According to jquery’s comments, it matches HTML strings and ID selectors
When I first looked at this regular expression, how could I match 0 or more non-< and also match Does this match < or not? And shouldn’t the html tag directly match
First (?:pattern) matches the pattern but does not get the matching result, which means that this is a non-getting match and is not stored for later use. And it will match everything that is not in parentheses.
The following is an example to illustrate
var quickExpr = /^(?:[^<]*(<[wW] >)[^>]*$|#([w-] )$)/;
sss="jytjt< dd1>1>fefef"
match=quickExpr.exec(sss);
alert(match);
The result is jytjt1>fefef =,1>
You can see that exec returns an array, and the second string is? : Match out the characters that are not < and non>
The method to obtain the result in jquery is also match[1]. So even if you enter extra html tags into jquery's selector, it can filter out the correct html tags. At the same time here? : It will also filter out the #, so you will get the id with only the id name and no # number.
So the meaning of this jquery regular expression is to filter html tags or id selectors
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn