benzhe
V2EX  ›  问与答

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

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