I'm trying to find if a given string of digits contains a sequence of three identical digits.
using a for loop, each digit in the string gets its own representation of a three digit sequence which is then checked against the string using Regex:
var str = "6854777322"
for(var i=0; i<str.length; i++)
{
seqToCompare = str[i] + str[i] + str[i];
var re = new RegExp(seqToCompare, "g");
if(str.match(re).length == 1)
{
match = str[i];
}
}
console.log(match)
The result should be seven (if I put 777 in seqToCompare, it would work), but it looks like the concatenation causes it to fail. Console shows "cannot read property length for null".
You can test it here - https://jsfiddle.net/kwnL7vLs/
I tried .toString, setting seqToCompare in Regex format and even parsing it as int (out of desperation for not knowing what to do anymore...)
nulland on the first iteration, the match does fail.