Regular Expressions - Reuse Patterns Using Capture Groups

What am I getting wrong pls? Who can help me out?

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

Your browser information:

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

Challenge: Regular Expressions - Reuse Patterns Using Capture Groups

Link to the challenge:

  1. Your regex will match only single digit numbers. You’ll need to modify the first capture group to allow for larger integers.
  2. Also, there’s an issue with using (\s) in this case, as this matches a space, a tab, a carriage return, a line feed, or a form feed. You can simply ditch the second capture group altogether and just explicitly put a single whitespace in between each \1.
  3. Your regex will match ‘42 42 42 42’, simply because you haven’t explicitly set the beginning and end of the string to match (using string anchors).

Thanks. your explanation worked a lot. I scaled through

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