Regular Expression {n, m} quantifiers (at least n times, at most m times), regular expression quantifiers

Source: Internet
Author: User

Regular Expression {n, m} quantifiers (at least n times, at most m times), regular expression quantifiers

Regular Expression {n, m} quantifiers:

{N, m}The quantifiers can repeat the previous matching characters for n-m times, at least n times, up to m times.

Syntax structure:
Constructor method:

New RegExp ("x {n, m }")

Method of direct object volume:

/X {n, m }/

Browser support:
Internet Explorer supports this metacharacter.
Firefox supports this metacharacter.
Google Chrome supports this metacharacter.

Instance code:

Instance 1:

Var str = "10000 or"; var reg = new RegExp ("\ d {}", "g"); console. log (str. match (reg ));

The above code can match three or four digits.

Example 2:

Var str = "10000 or"; var reg =/\ d {}/g; console. log (str. match (reg ));

This code serves the same purpose as the above Code. It is just a different definition of regular expressions.

It is recommended that you use this JavaScript Regular Expression online testing tool to view the results when learning.

As shown in the preceding figure, the three numbers only match 1000, and only 3-4 numbers are matched. If there are more than one number, the system will not work.

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.