推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
zncu
V2EX  ›  Python

新手请教个正则表达式的问题

  •  
  •   zncu · Mar 20, 2018 · 1442 views
    This topic created in 3121 days ago, the information mentioned may be changed or developed.
    print(re.findall("(as)|3","3as")) 为什么执行结果是 ['', 'as'] 怎么会出现一个空字符串呢,谢谢
    frostming
        1
    frostming  
       Mar 20, 2018   ❤️ 1
    https://docs.python.org/2/library/re.html#re.findall

    If one or more groups are present in the pattern, return a list of groups;

    如果有分组则返回分组,你这里有分组,但‘ 3 ’没有分组,所以匹配到了 3,仍返回了一个空
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1284 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:32 · PVG 00:32 · LAX 09:32 · JFK 12:32
    ♥ Do have faith in what you're doing.