小编Rol*_* Co的帖子

Regex that match exactly 3 identical consecutive numbers

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 --> …
Run Code Online (Sandbox Code Playgroud)

javascript regex capturing-group

6
推荐指数
1
解决办法
158
查看次数

标签 统计

capturing-group ×1

javascript ×1

regex ×1