-7

say I have a long string containing "abc""xyz""123" I'd like to split it into ["abc", "xyz", "123"] how? Thanks

2

2 Answers 2

0

Many ways to do it

Quick and dirty with split and filter out the empties

var string = '"abc""xyz""123"'
var result = string.split('"').filter(Boolean);
console.log(result);

Splitting with slice

var string = '"abc""xyz""123"'
var result = string.slice(1, string.length -1).split('""');
console.log(result);


A regular expression

var string = '"abc""xyz""123"'
var result = string.match(/[^"]+/g)
console.log(result);

Sign up to request clarification or add additional context in comments.

Comments

0
const input = '"abc""xyz""123"';

input.replace(/^"|"$/g, "").split('""'); // ["abc","xyz","123"]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.