I'm looking for a simple regular expression to match same character in the string more than two times likes following in java script. (Number 1 is three times) 112561
You could check if a group is more than tow times in the array.
console.log(/(.).*\1.*\1/g.test('12561'));
console.log(/(.).*\1.*\1/g.test('112561'));
console.log(/(.).*\1.*\1/g.test('2125611'));
The following regex can be used for this purpose:
.*(.).*\1.*\1.*
This will check if a character is repeated more than 2 times in a string. Note that this also does not use * which is a cause for performance issues in JavaScript.
console.log(/.+?(.)((?:.)+?\1){1,}/.test('abcZdefZghiZ'))
console.log(/.+?(.)((?:.)+?\1){1,}/.test('112561'))
console.log(/.+?(.)((?:.)+?\1){1,}/.test('12561'))