Q:

How do I use a JS regexp to match a string only if the regexp matches the entire string(no substring)

I am on this FCC challenge.  In this challenge, you are asked to create a regexp to match a string only if it has the same number repeated 3 times with spaces in between.  This means that a string with 4 numbers with spaces in between would not count as a valid match even though the regexp below would match it.  How could I modify my regexp to match a string ONLY IF it has a specific number repeated 3 times, no more, no less. 
let repeatNum = "42 42 42";
let reRegex = /(\d+)\s\1\s\1/; // Change this line
let result = reRegex.test(repeatNum);

What should I add into my code to make it valid only if a specific condition is valid for the entire string? 

A:

You can use ^ and $ to match the beginning and end of the string:

const re = /^(\d+) \1 \1$/;
console.log(re.test("42 42 42"));
console.log(re.test("42 42 42 42"));
console.log(re.test("42 42"));

