0

I'm making a program to split arguments in a string in Node.js, and I'm using .split(" "). Here's an example: "arg1 arg2 (arg3,arg4)"

This returns: ["arg1", "arg2", "(arg3,arg4)"] works as intended

But what I also want to do is take items in parentheses as 1 single object. For example: "arg1 arg2 (arg3, arg_after_space)"

Returns ["arg1", "arg2", "(arg3,", "arg_after_space)"] if using .split(" ")

What I want ["arg", "arg2", "(arg3, arg_after_space)"]

I want this to work with "", {}, (), [], and basically every symbol that is used as a pair in Node.js, but how can I do that?

I tried .split(" ") but just cannot figure out how to do that

HyperKNF
  • 13
  • 3
  • 2
    You’re basically inventing your own mini language, so will need your own mini parser. Is this really where you want to go? Isn’t there an easier way to express your data? – deceze May 11 '23 at 05:25
  • You have to include `"arg1 arg2 (arg3,arg_after_space)"`, because all you're separating are spaces – perona chan May 11 '23 at 05:52

0 Answers0