String separated by two different delimiters

I have strings like ' some-dasd\dasd-dasdas\dasdas-dasd-das\dsad '. I need to split a string into an array into two different characters '\' and '-' , so I would like to get an array ['some', 'dasd', 'dasd', 'dasdas', 'dasdas', 'dasd', 'das' ,'dsad'] .

What is the best way to do this?

+7
source share
2 answers
 "ome-dasd\dasd-dasdas\dasdas-dasd-das\dsad".split(/\\|-/) 

gotta do the trick.

+14
source

You can split the string with regexp:

  mystring.split(/[-\\]/) 
+11
source

All Articles