Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split string between two separators in javascript?

I know how to split using, multiple separators but I have no idea how to split a string into an array between two characters. So:

var myArray = "(text1)(text2)(text3)".split(???)
//=> myArray[0] = "text1", myArray[1] = "text2", myArray[2] = "text3"

What should I enter in the "???"? Or is there a different approach I should use?

Making ")(" a separator won't work as I want to split the array with a variety of separators such as ">" making it very unpractical to list every possible combination of separators

like image 725
curious-cat Avatar asked Nov 27 '12 22:11

curious-cat


1 Answers

.split(/[()]+/).filter(function(e) { return e; });

See this demo.

like image 163
Ωmega Avatar answered Oct 12 '22 01:10

Ωmega