Reuse Patterns Using Capture Groups Problem

Reuse Patterns Using Capture Groups Problem
0

#1

Tell us what’s happening:
I’m having trouble figuring out what exactly code camp is wanting my regular expression to look like. I cam up with one that works with all the test cases, but I still fail the check to see if I have only 2 spaces between each number. I made a regular expression that works correctly (using repeat groups as well as a beginning carat and negative lookahead), but it’s obviously not what they’re looking for. Can anyone help me out?

Your code so far


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

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/reuse-patterns-using-capture-groups


#2

I figured it out, they were wanting to see \s in two places, so I used

^(\d+)\s\1\s\1(?!.)

and it worked, in case anyone else needed help!