I have this string
\'john smith~123 Street~Apt 4~New York~NY~12345\'
Using JavaScript, what is the fastest way to parse this into
You can use split
to split the text.
As an alternative, you can also use match
as follow
var str = 'john smith~123 Street~Apt 4~New York~NY~12345';
matches = str.match(/[^~]+/g);
console.log(matches);
document.write(matches);
The regex [^~]+
will match all the characters except ~
and return the matches in an array. You can then extract the matches from it.