Regular Expressions - Reuse Patterns Using Capture Groups

I’m trying to solve it but keep getting the same error
Your regex should not match the string 42\t42\t42
how do I solve it

Your code so far

let repeatNum = "42 42 42";
let reRegex = /^(\d+)\s\1\s\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/110.0.0.0 Safari/537.36

Challenge: Regular Expressions - Reuse Patterns Using Capture Groups

Link to the challenge:

your pattern is matching all kinds of space characters (like the tab character).
You want to only match a single space character

I don’t understand what you mean only match a single space character

that’s from the requirements of the challenge. If you read it again it says:

match a string that consists of only the same number repeated exactly three times separated by single spaces.

Note the phrase: single spaces
It doesn’t say to match with any type of space. Only a ‘single space’.

I used a single space it still does not work

let repeatNum = “42 42 42”;

let reRegex = /^(\d+)\s\1\1$; // Change this line

let result = reRegex.test(repeatNum);

console.log(result)

\s is not a single space
it is a regex that will match all types of space characters include the tab character

I used the tab instead it still did not pass,idk what I’m doing wrong

let repeatNum = “42 42 42”;

let reRegex = /^(\d+) \1 \1$; // Change this line

let result = reRegex.test(repeatNum);

console.log(result)

the objective is to match the numbers with a single space between them
that means your pattern should have a single space between the capture groups.

for eg. here is a pattern that matches two letters with a space between them
/h h/
That blank space will match exactly one space between the letters.

Make sure your pattern is including a single space between the capture groups.

edit: also make sure your pattern starts and ends with a forward slash
(i think you are missing the ending slash)

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