The application of the small bracket of JS regular expression--regular expression

Source: Internet
Author: User
Tags regular expression

The main uses are the following three kinds:

1. (...)

Grouping. Group items into a single unit that can is used with *, +, ?, |, and,. Also Remember the characters that is the match this group for use with later references.

2. (?:...)

Grouping only. Group items into a single unit, but does not remember the characters of that match this group.

3.

(? =P) A Positive lookahead assertion. or

(?! P ) A negative lookahead assertion.

String used for testing: URL (skins/default/images/index/default.png)

The red character is the result of the match

The first, which is used for general grouping, remembers strings that match the group, and can later refer to the grouped groupings by \1

Eg: (\/) matching URL (skins/default/images/index/default.png)

(\/) default\1 matching URL (skins/default/images/index/default.png)

The second, for grouping, does not record the string that matches the group

Eg: (?: \ /) Default matching URL (skins/default/images/index/default.png)

The results of the first to second two ways of matching include the result that the packet matches, in the case of "/default" in the "/"

The third, which is used only to determine the location, does not contain the result that the bracket matches.

Eg: (?!) \/) Default matching URL (skins/default/images/index/default.png)

Eg:default (? =\/) matching URL (skins/default/images/index/default.png)

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.