To extract user names from a string, you can split the string at each occurrence of the @
symbol and then use the .map()
function to create an array of just the user names by applying a regular expression /,.*$/
that matches everything from the comma onwards.
For example:
var text = "rb40425,Fri Jan 30 11:35:33 2015@ot7293,Fri Jan....";
var users = text.split('@')
.map( function(item){ return item.replace( /,.*$/, '' ); } );
console.log( users.join('\n') );
If you prefer not to split the string, you can achieve the same result with:
var users = text.replace( /,.*?(@|$)/g, ',' );
console.log( users );
This approach will replace each comma along with all subsequent characters (but as few as possible) until it encounters either an @
symbol or reaches the end of the string.