2012-03-12 121 views

回答

4
var tweet = "hello to @you and @him!"; 
var users = tweet.match(/@\w+/g); 
console.log(users); // Will return an array containing ["@you", "@him"] 

然后,您可以剥除@只获取名称:

for (userIndex = 0; userIndex < users.length; userIndex++) 
    users[userIndex] = users[userIndex].substr(1); 

然后将返回数组作为

["you", "him"] 
相关问题