Reuse Patterns Using Capture Groups ##1


Can someone please explain the numbering system in this challenge? Thanks.

Your code so far

let repeatNum = "42 42 42";
let reRegex = /change/; // Change this line
let result = reRegex.test(repeatNum);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:

hello camper, captrue group is used to facilitate the search ,because some patterns some times are repeatead ,so it would be wastefull if you try to repeat regular expressions .


let repeatStr = "regex regex"; \\here regex is repeated so we should use captrue group
let repeatRegex = /(\w+)\s\1/; \\ this is what they did here  (\w+) =to match string regex  \s = to match space \1= means  this  groupe one refers to regex ,because it is repeated
repeatRegex.test(repeatStr); // Returns true
repeatStr.match(repeatRegex); // Returns ["regex regex", "regex"]

and remember to put the capture group between parantheses.