How do I split a string with multiple separators in javascript?

前端 未结 22 1573
走了就别回头了
走了就别回头了 2020-11-21 23:14

How do I split a string with multiple separators in JavaScript? I\'m trying to split on both commas and spaces but, AFAIK, JS\'s split function only supports one separator.

22条回答
  •  情话喂你
    2020-11-21 23:34

    I find that one of the main reasons I need this is to split file paths on both / and \. It's a bit of a tricky regex so I'll post it here for reference:

    var splitFilePath = filePath.split(/[\/\\]/);
    

提交回复
热议问题