I was checking a simple Regexp to check if a word has a letter or not, thus I ended using something like:
new RegExp(/[A-Z]/gi)
this regexp will be executed/tested each time that the user changes an input, lets suppose it is typing really fast, so I created this litte snippet:
const hasLettersExpression = new RegExp(/[A-Z]/gi);
const hasLetters = str => hasLettersExpression.test(str);
for (let i = 0; i < 10; i++) {
// we always test against the same string.
console.log(i, '--->', hasLetters('12ab'))
}
which from my perspective is giving the following result:
0 ---> true
1 ---> true
2 ---> false
3 ---> true
4 ---> true
5 ---> false
6 ---> true
7 ---> true
8 ---> false
9 ---> true
which is not correct, because it should always return true
.
does anyone know why is this happening? there is a patter of true, true, false
... is this related?