What’s the intent of () inside the regex? Thanks.
pattern.replace(/\{(\d+)\}/g,
function(pattern, index) {
return args[index].toString();
});
PS: args is something like [“3”, “dl1”, “42”]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is used to manage grouping.
The purpose of grouping is to make backreferences on searches & replaces. Using regex you can make that
Jhon DoebecomesDoe, Jhon.To achieve that, you would use a Regex
(\w*) (\w*)with two grups, and replace it for$2, $1Usually, the first group (0) references the whole match of the regex, being the other groups numbered according to the order where they are in your expression.