V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2013-08-10 09:21:18 +08:00 · 2791 次点击
    这是一个创建于 3923 天前的主题,其中的信息可能已经有所发展或是发生改变。
    re.search(r"(?:var).*",'var wumiiTitle ="some"').group())

    显示整个字符串 var wumiiTitle ="some"
    如果只要后面的,怎么写
    4 条回复    1970-01-01 08:00:00 +08:00
    qdcanyun
        1
    qdcanyun  
       2013-08-10 11:41:15 +08:00
    re.search(r"^var\s(.*)",'var wumiiTitle ="some"').group(1)
    GTim
        2
    GTim  
       2013-08-11 11:54:57 +08:00
    re.search(r'var.*?=\s*\"(.*?)\"',s).group(1)
    yakczh
        3
    yakczh  
    OP
       2013-08-12 16:52:44 +08:00
    group() 和group(0) 是不是一样?
    timonwong
        4
    timonwong  
       2013-08-12 17:09:33 +08:00
    @yakczh
    是的,除此之外还能接收多个group参数,请参阅python re模块的文档。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5934 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 02:59 · PVG 10:59 · LAX 19:59 · JFK 22:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.