Capture group help

Tell us what’s happening:
Describe your issue in detail here.
when I added ^ to the beginning of my code, just like in the solution, it worked. Before I put the ^ the only one failing with this code was "should not match 42 42 42 42 and I don’t understand why not putting ^ would make 42 42 42 42 match.

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/92.0.4515.107 Safari/537.36

Challenge: Reuse Patterns Using Capture Groups

Link to the challenge:

Without the ^ and with the trailing $, your regex says “ends with the same digits, repeated three times.” Doesn’t limit it to exactly three times on a line, simply that the line ends that way.

The leading caret and trailing dollar sign say “the text between these two symbols? that’s all that can be on the line.” The caret says the line must start with… And the dollar sign says must end with… And you explicitly say three times only on the line.

1 Like

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