regexp.exec() with g flag doesn’t recognize “catNip.jpeg” - why?
I know it works fine without g and also works with String’s .match(), but I don’t understand the reason.
When you use the g flag, the regex starts from the lastIndex which is the index at which it last found a match, so kitty-cat.png makes the lastIndex to 7, then in catNip.jpeg it starts checking from index 7, not 0, and finds nothing
this happens also with test, eventually you meet this and learn. use g only when you know you need it.
Ohhhh I think I get it. So, it basically doesn’t care that all the strings are different and keeps searching as if it was just one string passed all the time?