How can I split a JavaScript string by white space or comma?

前端 未结 6 540
遥遥无期
遥遥无期 2020-12-12 15:10

If I try

\"my, tags are, in here\".split(\" ,\")

I get the following

[ \'my, tags are, in here\' ]

Wherea

6条回答
  •  佛祖请我去吃肉
    2020-12-12 16:00

    When I want to take into account extra characters like your commas (in my case each token may be entered with quotes), I'd do a string.replace() to change the other delimiters to blanks and then split on whitespace.

提交回复
热议问题