I am currently using .split to try to split a string into different ‘tags’.
let text = "@yusra is cool @zain @chris is cool";
const myArray = text.split("@");
console.log(myArray);
The code above gives this output:
Array ["", "yusra is cool ", "zain ", "chris is cool"]
the expected output is:
Array ["yusra", "zain ", "chris"]
How do I modify this to make it do what I want.
>Solution :
Instead of using split you can use match to find the tags via a regex.
let text = "@yusra is cool @zain @chris is cool";
const myArray = text.match(/@\w+/g);
console.log(myArray);