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);


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -