0

Examples:

test "testing 123! :)" // -> ['test', 'testing 123! :)']

test "\"testing these are some nice quotes!\"" // -> ['test', '"testing these are some nice quotes!\"']

Is there anyway to do this with regex in JavaScript? Perhaps it could also work with --flag=value as well!

ToastOnAStick
  • 33
  • 3
  • 6
  • 2
    Does this answer your question? [Split a string by commas but ignore commas within double-quotes using Javascript](https://stackoverflow.com/questions/11456850/split-a-string-by-commas-but-ignore-commas-within-double-quotes-using-javascript). Just need to cusomize the REGEX. – DecPK May 28 '21 at 01:59

1 Answers1

0

Try it.

const exemple = `testA testB "testC testD  " testE `
const textArray = exemple
  .split(new RegExp(`("[\\s\\S]*")`, 'g'))
  .flatMap(text => text.match(`"`) ? text : text.split(`\\s+`))

Exemple image