benzhe
V2EX  ›  问与答

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

  •  
  •   benzhe · Jul 19, 2011 · 5005 views
    This topic created in 5419 days ago, the information mentioned may be changed or developed.
    8 replies    1970-01-01 08:00:00 +08:00
    yyfearth
        1
    yyfearth  
       Jul 19, 2011
    直接找/member/后面的不就可以了?
    chone
        2
    chone  
       Jul 20, 2011
    var html = document.innerHTML;
    html.match(/\/member\/[^\"]*.*class=\"dark\"/g).map(function(item){
    return item.match(/\/member\/([^"]*)/)[1];
    })
    chone
        3
    chone  
       Jul 20, 2011
    var html = document.body.innerHTML;
    漏了一个
    benzhe
        4
    benzhe  
    OP
       Jul 20, 2011
    @chone 谢谢,原来还需要一层map
    avatasia
        5
    avatasia  
       Jul 20, 2011
    @chone 求教 js 正则不是要new RegExp()么,这个html.match是什么语法?
    icyflash
        6
    icyflash  
       Jul 20, 2011
    yyfearth
        7
    yyfearth  
       Jul 20, 2011
    @avatasia 晕,用js的谁会去用new RegExp啊,有内建的符号不用/xxxx/igm。String.match(regex)
    chone
        8
    chone  
       Jul 20, 2011
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   983 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 21:48 · PVG 05:48 · LAX 14:48 · JFK 17:48
    ♥ Do have faith in what you're doing.