javascript - how to parse a JS usernames? -
my string is:
"@john @jerry @kerry hello world"
my goal obtain array:
["john","jerry","kerry", "hello world"];
infact @ marker username , last array item rest of string.
any idea ?
you can take rest of string , after can extract users , append last string in array.
var data = "@john @jerry @kerry hello world"; // rest of string var laststring = data.match(/ \w+/g).join('').trim(); // users var array = data.match(/@\w+/g).join('').split('@'); array = array.slice(1,array.length); // add rest of string end of array array.push(laststring);
var data = "@john @jerry @kerry hello world"; // rest of string var laststring = data.match(/ \w+/g).join('').trim(); // users var array = data.match(/@\w+/g).join('').split('@'); array = array.slice(1,array.length); // add rest of string end of array array.push(laststring); alert(array);