V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
benzhe
V2EX  ›  问与答

求举例,js正则如何把本页所有回复者的用户名抓出来

  •  
  •   benzhe · 2011-07-19 23:04:21 +08:00 · 4433 次点击
    这是一个创建于 4663 天前的主题,其中的信息可能已经有所发展或是发生改变。
    8 条回复    1970-01-01 08:00:00 +08:00
    yyfearth
        1
    yyfearth  
       2011-07-19 23:47:44 +08:00
    直接找/member/后面的不就可以了?
    chone
        2
    chone  
       2011-07-20 00:16:18 +08:00
    var html = document.innerHTML;
    html.match(/\/member\/[^\"]*.*class=\"dark\"/g).map(function(item){
    return item.match(/\/member\/([^"]*)/)[1];
    })
    chone
        3
    chone  
       2011-07-20 00:17:11 +08:00
    var html = document.body.innerHTML;
    漏了一个
    benzhe
        4
    benzhe  
    OP
       2011-07-20 03:21:51 +08:00
    @chone 谢谢,原来还需要一层map
    avatasia
        5
    avatasia  
       2011-07-20 09:51:42 +08:00
    @chone 求教 js 正则不是要new RegExp()么,这个html.match是什么语法?
    icyflash
        6
    icyflash  
       2011-07-20 10:02:57 +08:00
    yyfearth
        7
    yyfearth  
       2011-07-20 21:33:49 +08:00
    @avatasia 晕,用js的谁会去用new RegExp啊,有内建的符号不用/xxxx/igm。String.match(regex)
    chone
        8
    chone  
       2011-07-20 23:57:18 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3140 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:43 · PVG 22:43 · LAX 07:43 · JFK 10:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.