Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spliting string twice with 2 separators in javascript

Let's say I need to split the string a.b.c.d#.e.f.g.h#.i.j.k.l with separator as # and then ".".

str = a.b.c.d#.e.f.g.h#.i.j.k.l

res = str.split("#")

res[0] will store a.b.c.d when I use split for the 1st time .
I need to split this again and save the data.

can anyone help ?

like image 715
user3708154 Avatar asked Mar 27 '26 05:03

user3708154


1 Answers

I think the simplest way to do it is using a regex:

    var str = "a.b.c.d#.e.f.g.h#.i.j.k.l";

    var res = str.split(/[.#]/);
like image 61
Diogo Corrêa Avatar answered Mar 28 '26 17:03

Diogo Corrêa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!