I have a string like ";a;b;c;;e". Notice that there is an extra semicolon before e. I want the string to be split in a, b, c;, e. But it gets split like a, b, c, ;e.
My code is
var new_arr = str.split(';');
What can I do over here to get the result I want?
Regards
Use a Regexp negative lookahead:
  ";a;b;c;;e".split(/;(?!;)/)
                        Interesting, I get ["", "a", "b", "c", "", "e"] with your code.
var new_array = ";a;b;c;;e".split(/;(?!;)/);
new_array.shift();
This works in Firefox, but I think it's correct. You might need this cross-browser split for other browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With