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

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

  •  
  •   bostoneboy · 2011-05-06 23:02:12 +08:00 · 5059 次点击
    这是一个创建于 4732 天前的主题,其中的信息可能已经有所发展或是发生改变。
    接触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-05-06 23:58:14 +08:00
    re.search(r"a(\w+?)e", "abacdefge").group()
    vayn
        2
    vayn  
       2011-05-07 00:03:04 +08:00
    如果你有 Python 的问题可以发到 zhimaq.com 上或者 stackoverflow.com 上,一个是那里答题率很高,再一个是我可以赚点分:p
    bostoneboy
        3
    bostoneboy  
    OP
       2011-05-08 23:45:38 +08:00
    @vayn 多谢。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2722 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:28 · PVG 13:28 · LAX 22:28 · JFK 01:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.