nod*_*nja 1 javascript string twitter parsing
我想使用Javascript来解析推文并返回一个包含该推文中提到的人的数组.Twitter用户名都以@开头.假设我已经有了字符串,怎么办呢?
var tweet = "hello to @you and @him!";
var users = tweet.match(/@\w+/g);
console.log(users); // Will return an array containing ["@you", "@him"]
Run Code Online (Sandbox Code Playgroud)
然后,您可以剥离@只获取名称:
for (userIndex = 0; userIndex < users.length; userIndex++)
users[userIndex] = users[userIndex].substr(1);
Run Code Online (Sandbox Code Playgroud)
然后将返回数组作为
["you", "him"]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
735 次 |
| 最近记录: |