JQuery1.3.2 source code learning 2: two important regular expressions

Source: Internet
Author: User

32 // Is it a simple selector
33 isSimple =/^. [^: # \ [\.,] * $/

// Indicates that this is a regular expression.
^ Indicates the start part.
$ Indicates the end part.

. Match any character except \ n
[^ Character_group] indicates that it is not in the character set.
[^: # \ [\.,] Indicates any character except the colon (:), #, brackets ([), periods (.), and commas (,).
[^: # \ [\.,] * Indicates the repetition of any of the above characters from 0 to any times.

29 // A simple way to check for HTML strings or ID strings
30 // (both of which we optimize)
31 var quickExpr =/^ [^ <] * (<(. | \ s) +>) [^>] * $ | ^ # (\ w +) $ /;

The content of the regular expression is ^ [^ <] * (<(. | \ s) +>) [^>] * $ | ^ # (\ w +) $

| Or, the expression is divided into two parts.
^ [^ <] * (<(. | \ S) +>) [^>] * $

[^ <] Indicates any character except <
[^ <] * Indicates any number of characters except <

\ S indicates any blank characters, such as spaces, carriage return, and tabulation.
. | \ S represents any character
(. | \ S) + represents any number of characters. Note that it is greedy because it is a plus.
<(. | \ S) +> indicates that the string starts with <, and any character in the middle ends with>, which is the longest string that begins with <and ends with>.
[^>] * Indicates any number of characters except>

In combination, it means that there are multiple arbitrary characters except <, starting with any string in the middle, followed by>, finally, it is a string of any number of characters except>, that is, an html string.

Followed by ^ # (\ w + )&

\ W represents any word character, that is, a [a-zA-Z_0-9].
\ W + indicates more than 1 Character
# (\ W +) indicates more than one word character starting with #, that is, the ID format in jQuery.

Three parentheses are used to indicate the group. If the first group is matched, the subscript is 1, and the third group is matched, the ID is used.

Source: blog

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.