Continuing the discussion from Reuse Patterns Using Capture Groupz:
In this solution, we are basicly saying there should be nothing before and after what we are looking for, are there any other solutions to this puzzle?
let repeatNum = "42 42 42";
let reRegex = /^(\d+)\s\1\s\1$/;
let result = reRegex.test(repeatNum);
other than writing something like /^(\d+)(\s\1)\2^/ which is mostly the same thing, I don’t think there is much variation here, considering the objective is to match a specific pattern
you could use [0-9] instead of \d, you could use the counter {1,} instead of +, but they mean the same thing
Regex is for matching strings. That string is the character “4” then the character “2” then the character " " then the character “4” then the character “2” then the character " " then the character “4” then the character “2” then the character " " then the character “a”.
There isn’t any such thing as a number (like 42) in a string. There are characters that represent numbers, but they are just characters. When you use \d that means match one of the characters “0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8” or “9”. Regex has no idea what a mathematical number is
I don’t know, the example seems to point to that, plus the tests…
also, it would be too complex for a simple challenge like that to have something like a 24 24 24 a be matched, but not something like a 24 24 24 24 a
the example shows /(\w+)\s\1/
probably with lookaheads and lookbehinds…
also, a 24 24 24 24 a should not pass, but what about a 24 24 24 23 a? there is not enough infos on all those other edge cases to think that it asks more than that