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?
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.
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)
Hi. I have the same problem. Cannot understand why the caret works here.
In the previous challenges caret was explained as follows: To create a negated character set, you place a caret character (^ ) after the opening bracket and before the characters you do not want to match.
Why /^(\d+) \1 \1$/ works for the task “match a string that consists of only the same number repeated exactly three times” if the caret is meant for “characters you do not want to match.” ?
How the ^ works changes depending on where it is used in the regex. In the one you just posted ^ is saying “this needs to be at the beginning of the string”. But in [^a] its saying “match anything that is not the letter a”.
I normally use https://regex101.com/ to test and understand what a regex is doing, because it breaks it down into nice pieces in the top right that help me understand everything going on in it. it also has a nice cheat sheet in the lower right.