简体   繁体   English

字符串由两个不同的分隔符分隔

[英]String split by two different delimiters

I have strings like this ' some-dasd\\dasd-dasdas\\dasdas-dasd-das\\dsad '. 我有这样的字符串' some-dasd\\dasd-dasdas\\dasdas-dasd-das\\dsad '。 I need to split the string to array by two different symbols '\\' and '-' , so I would like to get the array ['some', 'dasd', 'dasd', 'dasdas', 'dasdas', 'dasd', 'das' ,'dsad'] . 我需要通过两个不同的符号'\\''-'将字符串拆分为数组,所以我想得到数组['some', 'dasd', 'dasd', 'dasdas', 'dasdas', 'dasd', 'das' ,'dsad']

What is the best way to do it? 最好的方法是什么?

"ome-dasd\dasd-dasdas\dasdas-dasd-das\dsad".split(/\\|-/)

应该做的伎俩。

您可以使用regexp拆分字符串:

 mystring.split(/[-\\]/)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM