推荐学习书目
› 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 · May 6, 2011 · 6149 views
    This topic created in 5625 days ago, the information mentioned may be changed or developed.
    接触python不久,各位多指教。

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

    我想要使后面匹配的那个e在第一次搜索时就结束,也就是返回结果:abacde
    这个该怎么实现?前提是中间组的匹配仍是(\w+)
    3 replies  •  1970-01-01 08:00:00 +08:00
    vayn
        1
    vayn  
       May 6, 2011
    re.search(r"a(\w+?)e", "abacdefge").group()
    vayn
        2
    vayn  
       May 7, 2011
    如果你有 Python 的问题可以发到 zhimaq.com 上或者 stackoverflow.com 上,一个是那里答题率很高,再一个是我可以赚点分:p
    sinmabb
        3
    sinmabb  
    OP
       May 8, 2011
    @vayn 多谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2604 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:03 · PVG 21:03 · LAX 06:03 · JFK 09:03
    ♥ Do have faith in what you're doing.