Regular Expressions - Reuse Patterns Using Capture Groups

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

let repeatNum = "42 42 42";
let reRegex = /^(\d+)\s\1\s\1$/;// Change this line
let result = reRegex.test(repeatNum);

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; ART-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.134 Mobile Safari/537.36 OPR/70.3.3653.66287

Challenge: Regular Expressions - Reuse Patterns Using Capture Groups

Link to the challenge:

Opps, somehow the your \s accidentally caught \t . Maybe you want to try something elese… how about a spacebar.

That’s technically correct but you have to remember that \s != ' '

Actually, \s = [ \t\n\r\f\v]

So, to exactly match that string, just substitute the \s for ' '

And the RegEx reads:
1- ^ = Matches the beggining of a string.
2- Create capture group #1.
3- \d = digits [0-9].
4- + = match 1 or more of the preceding character/token.
5- " " = match 1 empty space.
6- \1 = Numeric reference that matches results represented by capture group #1.
7- $ = Matches the end of a string.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.