By parsing the table into an array of each row as a concatenated string, you can execute the regular expression in the row and apply the necessary CSS to the fragment of the children in this row using the range of substrings returned by the regular expression.
$("table").find("tr").each(function (line, row) {
var children = $(row).children("td");
var numbers = children.map(function (_, data) {
return data.innerHTML;
});
var expression = new RegExp(/([0-9])\1{2,}/, "g");
var string = numbers.get().join('');
var result = expression.exec(string);
while (result) {
var length = result[0].length;
var number = result[1];
var start = result.index;
var end = start + length;
children.slice(start, end).each(function (_, child) {
$(child).css('color', 'red');
});
$("#results").append(
'<span>Number ' + number +
' was repeated ' + length +
' times on line ' + line + '.' +
'</span><br>'
);
result = expression.exec(string);
}
});
https://jsfiddle.net/ews8t955/1/
source
share