Home >Web Front-end >JS Tutorial >Regular expression description in jquery_jquery

Regular expression description in jquery_jquery

WBOY
WBOYOriginal
2016-05-16 18:03:541261browse

// 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

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

Copy the code The code is as follows:

var quickExpr = /^(?:[^<]*(<[wW] >)[^>]*$|#([w-] )$)/;
sss="jytjt< dd1>fefef"
match=quickExpr.exec(sss);
alert(match);

The result is jytjtfefef =,

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