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

请教一个正则问题,懒惰匹配如何匹配多个内容

  •  
  •   wonder1z · Nov 22, 2018 · 2801 views
    This topic created in 2913 days ago, the information mentioned may be changed or developed.
    str = 'asd(hello)asd(world)'
    s = re.search(r'(?<=\().*?(?=\))',str1)
    print(s)
    
    <re.Match object; span=(4, 9), match='hello'>
    

    只能匹配出第一个 hello,如何匹配出所有()里的内容呢

    6 replies  •  2018-11-22 16:14:11 +08:00
    masker
    masker
    Nov 22, 2018 via Android
    1
    \w+\((.*?)\){1,}
    sess222
    sess222
    Nov 22, 2018❤️1
    2
    懒惰匹配是虾米?
    re.findall('\((.*?)\)', str1)
    wonder1z
    wonder1z
    OP
    Nov 22, 2018
    3
    @masker 老铁 你这个不对啊
    wonder1z
    wonder1z
    OP
    Nov 22, 2018
    4
    @sess222 这个也不对的,懒惰就是尽可能少的重复
    wonder1z
    wonder1z
    OP
    Nov 22, 2018
    5
    @sess222 sorry 搞错了,你这个可以的
    Atukey
    Atukey
    Nov 22, 2018
    6
    (?<=\()\w*(?=\))
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2054 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 01:32 · PVG 09:32 · LAX 17:32 · JFK 20:32
    ♥ Do have faith in what you're doing.