1

Having the following js code:

const text = '>>>>\n>>>>\n';
const regex = /^>.*$/ig;

let lines = text.split(/\r?\n/);

let i = lines.length - 1;
if (lines[i] === '') {
  i -= 1;
}

console.log(regex.test(lines[i]));
console.log(regex.test(lines[i]));
console.log(regex.test(lines[i]));
console.log(regex.test(lines[i]));

It outputs:

true
false
true
false

But I expect all outputs to be true. Is there anything I misunderstand?

Zhe Chen
  • 2,918
  • 4
  • 23
  • 39

0 Answers0