更新时间:2023-02-19 09:29:58
var tweet = "hello to @you and @him!";
var users = tweet.match(/@\w+/g);
console.log(users); // Will return an array containing ["@you", "@him"]
然后,您可以剥离@
以仅获取名称:
Then, you can strip the @
to only get the names:
for (userIndex = 0; userIndex < users.length; userIndex++)
users[userIndex] = users[userIndex].substr(1);
然后将其返回为
["you", "him"]