Reputation: 19
I have a variable
var i = "my*text+val-ab/c"
I want to split it using special characters *
, +
, -
and /
. I mean, I want to generate:
var one = "my", var two = "text", var three = "val"
from the above variable.
How can I do this using jQuery and (or) Javascript?
var ret1 = id.split("+");
Thanks in advance...
Upvotes: 0
Views: 487
Reputation: 521073
Try splitting on a character class containing all symbols:
var i = "my*text+val-ab/c";
var parts = i.split(/[*,+=\/-]/);
console.log(parts);
Upvotes: 3