0

Why does this regex alternate between true and false? It seems like it should match the "approv" at the beginning and always return true. No matter what, it doesn't seem like it should alternate.

const filter = /(approv)/gi // Also happens with /.*(approv).*/gi
console.log(
  filter.test("approv"),
  filter.test("approve"),
  filter.test("approvd"),
  filter.test("approved!"),
  filter.test("approved!!"),
  filter.test("approved!!!")
)
Daniel
  • 1,392
  • 1
  • 5
  • 16

0 Answers0