Created
July 1, 2017 06:58
-
-
Save yano3nora/a8398dd049fae106733b256c37af0f79 to your computer and use it in GitHub Desktop.
[js: command line parse] command line string parse. #js #regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cmd = "> create user name \"comment comment\""; | |
var reg = new RegExp(/\s+(?:"((?:\\"|[^"])*)"?|([^"]\S*))/); | |
var inputArray = []; | |
inputArray = cmd.split(reg); | |
var cmds = []; | |
for (var i = 0; i < inputArray.length; i++) { | |
if (inputArray[i]) { | |
cmds.push(inputArray[i]); | |
} | |
} | |
console.dir(cmds); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment