In a regular expression, what are the differences between "+", "*", "." and? Non-escape

Source: Internet
Author: User
For example, what is the difference between the {code...} symbols in [] and those outside? For example:

[\ W.] + and [\ w. + *?]

What is the difference between these symbols and the outside in?

Reply content:

For example:

[\ W.] + and [\ w. + *?]

What is the difference between these symbols and the outside in?

First, the Regular Expression[]The content indicates the meaning of the optional combination,
Similar

/[\w.]/.test("a"); // true/[\w.]/.test("."); // true/[\w.]/.test("a."); // true/[\w.]/.test(" "); // false

The above regular expression can match one character or a dot in an optional combination, but cannot match null characters;

Differences:
1..In[]It is used to match.It is used to match any character outside, as shown in the following example:

/./.test(" "); //true/[.]/.test(" "); //false

2.*And+In[]It is called a quantizer (quantizer of a number). It indicates the quantity to be matched,
*Indicates any number, and the Set indicates yes[0, +00);
+Indicates at least 1 time, And the set indicates yes[1, +00);
It must be said that, when used as a quantizer,*And+Follow the regular expression (partial) that matches the meaning );
In[]It indicates its own meaning, in order to match*Or+;

/[+]/.test("+"); //true/+/.test(""); //Uncaught SyntaxError: Invalid regular expression: /+/: Nothing to repeat(…)/.+/.test("oops"); //true

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.