I am currently revising one of my scripts and have come across a perplexing issue. The variable command
is an input, and I conducted the following test with identical regular expressions:
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));
When I check the console, it displays:
true
[]
["view", "-10", "10", "-10", "10"]
This situation has left me completely baffled. Why is the separation of command
not the same, despite being identical to my test string and using ===
?