# The purpose of the parentheses in the regular () is detailed

Source: Internet
Author: User

The parentheses in the regular expression function to group the characters and save the matching text. Today we are going to discuss in detail the use of the parentheses () in the next regular round, and I hope we can help you with your study.

First, as we mentioned earlier, if the second parameter in the Replace () method is a callback function, then the parameter in the callback function is the result of the match success .... , do you think there are multiple parameters in the callback function?

Let me give you an example:

?

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19-20

The above example requires you to look at the value of A1,A2,A3 separately, and you will find some regularity

View a1:2015-8-individually

View a2:2015 8 individually

View a3:-individually-

Three parameters of the image of an analogy, A1 equivalent to the mother, A2 is the older son, A3 is the youngest son, each of the sons have inherited a part of the mother's genes

A1 is Var re=/d+-/g; The results of this regular

A2 is Var re=/(d+) (-)/g; The result of the first bracket on the left

A2 is Var re=/(d+) (-)/g; The result of the second parenthesis on the left

With the use of so many parameters, let's implement the output below: 2015.8.7

Method one: to the son operation

?

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Method Two: to the mother operation

?

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

The relationship between the multiple parameters of the callback function of the replace () method in the regular and the parentheses is found to be complicated.

What is the difference between the bracket [] of the regular expression and the parentheses ()?

The basic meaning: the parenthesis is the parentheses as a whole, the bracket is to match one of the parentheses, the braces are matched several times

But there are different meanings in parentheses and other characters. Detailed Introduction For example:

N

n is a non-negative integer. Match the determined n times. For example, "o{2}" cannot match "O" in "Bob", but can match two o in "food".

{N,}

n is a non-negative integer. At least match n times. For example, "o{2,}" cannot match "O" in "Bob", but can match all o in "Foooood". O{1,} "is equivalent to" o+ ". O{0,} "is equivalent to" o* ".

{N,m}

M and n are non-negative integers, where n

[] meaningless, generally used to match a set

Like what

[0-9]: Find any number from 0 to 9.

[A-Z]: Find any character that writes a to uppercase Z from small.

() also matches a collection, but it can also be used as a reverse reference.

The above mentioned is the entire content of this article, I hope you can enjoy.

Related Keywords:
Related Article

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD