airyland
V2EX  ›  问与答

求教正则表达式。

  •  
  •   airyland · Aug 23, 2011 · 4474 views
    This topic created in 5377 days ago, the information mentioned may be changed or developed.
    正则获取里@后面的用户名,用下面的php代码只能获取第一个用户名,如何获取所有的呢?

    $par = "/@(.*?)\s+/is";
    preg_match($par, $string,$arr);
    2 replies    1970-01-01 08:00:00 +08:00
    wctbok
        1
    wctbok  
       Aug 23, 2011
    全局匹配要用 preg_match_all 函数,手册上有详细说明。
    airyland
        2
    airyland  
    OP
       Aug 23, 2011
    @wctbok 是的,刚刚才翻到,囧。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3749 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 04:55 · PVG 12:55 · LAX 21:55 · JFK 00:55
    ♥ Do have faith in what you're doing.