I'm making a JS "command line" emulator.
I have Regexp: /([^\s"]+)|"([^\s"]+)"/g.
I want to match single words, like echo, wyświetl, jd923h90asd8. Also, I want to match "string literals" - something like "this is a string" or "f82h3 23fhn aj293 dgja3 xcn32".
I'm using match method on input string to get array of all matches. But problem is:
when Regexp matches "string literal" and returns string to array, this string INCLUDES double-quotes. I don't want double-quotes, but the question is - why Regexp includes double-quotes? In the Regexp, quotes "" are excluded from () group. Why Regexp includes it all?
EDIT:
var re = /([^\s"]+)|"([^\s"]+)"/g;
var process = function (text) {
return execute(text.match(re));
}
var execute = function (arr) {
console.log(arr);
try {
//... apply a function with arguments...
} catch (e) {
error(arr[0]+": wrong function");
return "";
}
}
For input echo abc "abc def" "ghi" Regexp returns array ["echo", "abc", "abc", "def", ""ghi""].
I want to make a Regexp, that from that input will return ["echo", "abc", "abc def", "ghi"].
sort varnameto have a different meaning thansort "varname".