The role of \1\2 in JavaScript regularization

Source: Internet
Author: User
One, example 1. Verify 6 identical numbers
var reg = new RegExp (/^ (\d) \1{5}/g), var a = ' 333333 ', if (Reg.test (a)) {alert (' Right '),} else {alert (' wrong ');}
2. Verify 3 identical numbers + 3 identical letters
var reg = new RegExp (/^ (\d) \1{2} ([A-z]) \2{2}/g), var a = ' 333aa1 ', if (Reg.test (a)) {alert (' Right '),} else {alert (' WR Ong ');}
Second, explanation:

\1 must be used in conjunction with parentheses.

The parentheses "()" in the regular expression. is meant to represent the grouping. If the \1 appears later, the representation is the same as the one in the first parenthesis. Link

The role of \1\2 in JavaScript regularization

This article from "Do not know not to ask" blog, please be sure to keep this source http://mazey.blog.51cto.com/12997993/1975323

The role of \1\2 in JavaScript regularization

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.