It's my understanding that all three of these lines below should return an ARRAY with 2 results in it. Yet RegExp will only return 1 result no matter how many times the regex repeats in the string.
Can some one explain why? And perhaps suggest how I can get RegExp to give me global results?
//INTPUT:
console.log(new RegExp("New York", "gi").exec("New York New York"));
//OUTPUT:
["New York"]
//INTPUT:
console.log(new RegExp(/New York/gi).exec("New York New York"));
//OUTPUT:
["New York"]
//INTPUT:
console.log("New York New York".match(/New York/gi));
//OUTPUT:
["New York", "New York"]
(' New York New York ').match(/ New York /gi)it will bring just 1 result (as kinda expected) and I can't think of a better way to go around this (when otherwise needed) other than iterating over it! :(