I know this question had been asked before in numerous variations but I can't seem to merge all the data to a working solution
Motivation
I have a JScript
running under WSH
. However, this is essentially a simple javascript
| regexp
question
I'm trying to parse a string. requirements:
- Split it by multiple delimiters:
-
,=
- Ignore delimiters wrapped in double quotes
- Keep the delimiters in the result
Example
This is the string I've been working with. double quotes are part of the string
"C:\\Users\\u 1\\a-b\\f1.txt" -CONFIG="C:\\Users\\u 1\\c=d\\f2.xfg"-ARGS=/quite /v1
expected results after split
"C:\\Users\\u 1\\a-b\\f1.txt"
-
CONFIG
=
"C:\\Users\\u 1\\c=d\\f2.xfg"
-
ARGS
=
/quite /v1
Failed attempt
var str = '"C:\\Users\\u 1\\a-b\\f1.txt" -CONFIG="C:\\Users\\u 1\\c=d\\f2.xfg"-ARGS=/quite /v1';
var res = str .split(/-(?=(?:(?:[^"]*"){2})*[^"]*$)/);
Failed Result:
\"C:\\Users\\u 1\\a-b\\f1.txt
CONFIG=\"C:\\Users\\u 1\\c=d\\f2.xfg\"
ARGS=/quite /v1