Good morning all,
I want to make a regex that match 3 same consecutive numbers. It should match only 3 numbers in a row (separated by a space), the numbers should be identical. If there are less or more than 3 same numbers, then the output should be false
I have tried this regex /.*(\d+) \1 \1(?!(\s\1))/
console.log(/.*(\d+) \1 \1(?!(\s\1))/.test('I am 42 42 4 hey yoo')); //false --> Correct
console.log(/.*(\d+) \1 \1(?!(\s\1))/.test('I am 42 42 42 hey yoo')); //true --> Correct
console.log(/.*(\d+) \1 \1(?!(\s\1))/.test('I am 42 42 42 4 hey yoo')); //true --> Correct
console.log(/.*(\d+) \1 \1(?!(\s\1))/.test('I am 42 42 42 42 hey yoo')); //true --> this output should be false since there are 4 same consecutive digits
Any advice, please?
foo 42 42 42 bar 42 42 42 42
? Should that match or not? – Gnarl^(?!.*?(?: |^)(\d+)(?: \1){3}(?!\S)).*?(?: |^)(\d+)(?: \2){2}(?!\S)
– Amimia"I am^42 42 42 hey yoo"
whereas I do not (as I require the first"42"
to be preceded by a space or be at the beginning of the string). Neither set of assumptions is correct; it's whatever you want. – Nicaragua