Tell us what’s happening:
Describe your issue in detail here.
I don’t understand what am I doing wrong here. can anyone help ??
Your code so far
let repeatNum = "42 42 42";
let reRegex = /(\d+) \1 \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/188.8.131.52 Safari/537.36
Challenge: Regular Expressions - Reuse Patterns Using Capture Groups
Link to the challenge:
You are almost there! Remember that you are asked to match only strings that are exactly one number repeated three times with spaces in between – no more or less. For example, you should not match
"10 10 100" or
"hello 5 5 5 goodbye".
What can you do to ensure that you only match an entire string, and not a substring of a larger string?
I tried this as well: (\d+) \1 \1$; but it says regex should not match the string 42 42 42 42
The dollar sign means that nothing can come after the expression, but does not affect what can come before. That means that in the case of
42 42 42 42, it will match the final three 42s.
You need to add one more symbol to indicate that nothing can come before the expression.
I added caret sign in the beginning it worked. I had already tried using those signs but separately so that’s why the test was failing.
In the future, I recommend using a website like https://regexr.com/ or https://www.regexpal.com/ to help you when developing regular expressions. You can put in a test string and see exactly what does or does not match, you can mouseover symbols in the expression to get an explanation of their function, and regexr can additionally allow you to set up a series of tests just like the ones you have to pass on FCC.
These tools can save you a lot of headaches!
(I personally prefer regexr because it has many more useful features)