In regular expressions "+", "*", "." What is the difference between [] within and outside? Non-escaping

Source: Internet
Author: User
Keywords Regular Expressions PHP
For example:

[\w.]+和[\w.+*?]

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

Reply content:

For example:

[\w.]+和[\w.+*?]

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

First [] , the contents of the regular expression represent the meaning of the optional combination,
Similar

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

The optional combination of the above regular expression can match a character, or a dot, but cannot match the null character;

Tell me the difference:
1. . in [] the inside, it is to match . , in the outside when it is used to match any character, see the following example:

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

2. * and + on the [] outside is called the quantifier (quantifier of the quantity word), is to indicate the quantity to match,
*Represents any number, which is represented by a set [0, +00) ;
+Represents at least 1 times, the set represents Yes [1, +00) ;
It has to be said that, as a quantifier, * and the + preceding must follow the meaning of the regular expression (part);
Within it means the [] meaning of itself, 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.