I have this code that when I remove the g
lobal flag, it is matching an extra fox
:
var str = "...brown #fox jumped...";
var arr1 = str.match(/#([^\s]+)/g); //["#fox"]
var arr2 = str.match(/#([^\s]+)/); //["#fox", "fox"]
console.log(arr1.join(", ")); //#fox
console.log(arr2.join(", ")); //#fox, fox
demo
I don't have a clue what is going on, anything that enlightens me is welcome