推荐学习书目
› 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
vtoexsir
V2EX  ›  Python

python 正则怎么获取全部 match 对象?

  •  
  •   vtoexsir · Oct 13, 2016 · 2934 views
    This topic created in 3634 days ago, the information mentioned may be changed or developed.
    import re
    s='aabbaa'
    s 字符串或有 4 个字符 a.
    md=re.search('a',s) #但 search()返回的是 s 字符串中第一匹配到的 match 对象
    fa=re.findall('a',s) #这个findall()找到了所有4个匹配,但返回的是匹配得到的字符串,而不是match对象.
    mds=re.scan('a',s) #我想得到全部 4 个匹配到的 match 对象,但是 python 没有 scan()方法?该怎么办呢?
    如果自己手动实现,是可以的,但我想这是个很常用的功能,python 不会不内置解决方法吧?
    请各位指点!
    2 replies  •  2016-10-14 08:58:24 +08:00
    binux
        1
    binux  
       Oct 13, 2016   ❤️ 1
    re.finditer
    Cabana
        2
    Cabana  
       Oct 14, 2016
    用 pattern find
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2491 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 11:08 · PVG 19:08 · LAX 04:08 · JFK 07:08
    ♥ Do have faith in what you're doing.