我曾尝试在 JS 中拆分字符串,例如..
'a b c' => ['a','b','c']
'a bb cc dd' => ['a','bb','cc','dd]
'a "bb cc" dd' => ['a','bb cc', 'dd']
"a 'bb cc' dd" => ['a','bb cc', 'dd']
我如何在 JS 正则表达式中做到这一点?我试过了
/\w+|"(?:\\"|[^"])+"/g
但它返回...
'a b c' => ['a','b','c']
'a bb cc dd' => ['a','bb','cc','dd]
'a "bb cc" dd' => ['a','"bb cc"', 'dd']
"a 'bb cc' dd" => ['a','bb','cc', 'dd']