V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
gaolinjie

匹配用户昵称的正则表达式

  •  
  •   gaolinjie · Feb 1, 2013 · 2311 views
    This topic created in 4847 days ago, the information mentioned may be changed or developed.
    之前没学过正则,现有的代码可以提取@后的英文用户名,现在想扩展可以提取@后含英文、数字、下划线和汉字的昵称,请问这个正则怎么写啊?

    现有的代码:
    ```
    import re

    def find_mentions(content):
    regex = re.compile(r"@(?P<username>\w+)(\s|$)", re.I)
    return [m.group("username") for m in regex.finditer(content)]
    ```
    1 replies    1970-01-01 08:00:00 +08:00
    paloalto
        1
    paloalto  
       Feb 1, 2013
    哈哈 刚好昨天也在写这个.

    http://gist.github.com/4689495

    再把汉字的正则也加上就行啦。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3458 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 11:21 · PVG 19:21 · LAX 04:21 · JFK 07:21
    ♥ Do have faith in what you're doing.