Use RegExp with JavaScript split()

September 11, 2012 – 11:39 am

Here is a short snippet the came out of a forum post here.

I you have a string that, for whatever reason, is concatenated using different delimiters, you can use regexp with javascript split() to build an array of single values.

var s = "one#two#three~four~five";
 
s.split(/[#~]+/);

The output will be an array containing 5 elements

Sorry, comments for this entry are closed at this time.