Regular Expression description in jquery

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.