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