I'm rewriting one of my scripts right now and encountered a problem I just can't figure out. command
is an input variable and now I've run this test (both regular expressions are the same):
var parts = command.match(/([^\s"]+(?=\s*|$))|(".+?")/g);
console.log(command === "view -10 10 -10 10");
console.log(parts);
console.log(String("view -10 10 -10 10").match(/([^\s"]+(?=\s*|$))|(".+?")/g));
The console now says
true
[]
["view", "-10", "10", "-10", "10"]
This completely confuses me. Why does command
not get separated the same way, when it equals my test string even when using ===
?