Reuse patterns using capture

Tell us what’s happening:
I dont really understand why this does not work. To me, it checks out. Anyone can help?
Your code so far

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.

Challenge: Reuse Patterns Using Capture Groups

Link to the challenge:

You are almost there and the main logic is good. but without a ^ at the beginning of your regex this can match the last three numbers of any repeating series of the same number. Such as: 2 2 2 2 would find a match in the last three 2s.

EDIT: i use this website extensively when building regex from scratch. the visualization and resources are super helpful:

1 Like

I just had an Aha moment. Thank you! and thanks for the link as well.

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