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

match.group() 也包含非捕获组吗?

  •  
  •   yakczh · Aug 10, 2013 · 3367 views
    This topic created in 4665 days ago, the information mentioned may be changed or developed.
    re.search(r"(?:var).*",'var wumiiTitle ="some"').group())

    显示整个字符串 var wumiiTitle ="some"
    如果只要后面的,怎么写
    4 replies    1970-01-01 08:00:00 +08:00
    qdcanyun
        1
    qdcanyun  
       Aug 10, 2013
    re.search(r"^var\s(.*)",'var wumiiTitle ="some"').group(1)
    yemoluo
        2
    yemoluo  
       Aug 11, 2013
    re.search(r'var.*?=\s*\"(.*?)\"',s).group(1)
    yakczh
        3
    yakczh  
    OP
       Aug 12, 2013
    group() 和group(0) 是不是一样?
    timonwong
        4
    timonwong  
       Aug 12, 2013
    @yakczh
    是的,除此之外还能接收多个group参数,请参阅python re模块的文档。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1463 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 16:53 · PVG 00:53 · LAX 09:53 · JFK 12:53
    ♥ Do have faith in what you're doing.