A question about regular expressions

Source: Internet
Author: User

Add another question.
(. +), (.) +, And. + are not the same?
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

Why are the running results of the above code different?
Some results are separated by commas. Why?Copy codeThe Code is as follows: exec () returns an array that matches the content that matches the pattern (composed of the entire array and the Child parts that are arranged in a forward order). When displayed with alert, the array toSting () is displayed () result (a string separated by commas ).
In the regular expression. (point) represents any character except the line break (when the m parameter is added to enable multi-line match mode, it represents any character), with the escape symbol \. indicates the point character ontology.

Copy codeThe Code is as follows: var Pattern3 =/<(.) +>/I;
Alert(Pattern3.exe c ("<p align = center onclick = dsa>") [1])
Why do we get a instead of p?

Test alert(pattern3.exe c ("<p align = center onclick = dsa6>") [1]). 6
(.) + Match all the way and return the result in the final match.

+ (Plus sign) indicates the plus pattern (or pattern fragment). If there are at least one, there may be multiple.

The content enclosed by () in the regular expression is considered as a child part of the pattern and will be reflected in exec.

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.