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
sinmabb
V2EX  ›  Python

请教python中正则表达式的一个小问题。

  •  
  •   sinmabb · 2011 年 5 月 6 日 · 5687 次点击
    这是一个创建于 5374 天前的主题,其中的信息可能已经有所发展或是发生改变。
    接触python不久,各位多指教。

    re.search(r"a(\w+)e","abacdefge").group() 这个的结果是:abacdefge

    我想要使后面匹配的那个e在第一次搜索时就结束,也就是返回结果:abacde
    这个该怎么实现?前提是中间组的匹配仍是(\w+)
    3 条回复    1970-01-01 08:00:00 +08:00
    vayn
        1
    vayn  
       2011 年 5 月 6 日
    re.search(r"a(\w+?)e", "abacdefge").group()
    vayn
        2
    vayn  
       2011 年 5 月 7 日
    如果你有 Python 的问题可以发到 zhimaq.com 上或者 stackoverflow.com 上,一个是那里答题率很高,再一个是我可以赚点分:p
    sinmabb
        3
    sinmabb  
    OP
       2011 年 5 月 8 日
    @vayn 多谢。
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   5534 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 09:00 · PVG 17:00 · LAX 01:00 · JFK 04:00
    ♥ Do have faith in what you're doing.