V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 5839 views
    This topic created in 5470 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   ·   Solana   ·   1062 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 18:48 · PVG 02:48 · LAX 11:48 · JFK 14:48
    ♥ Do have faith in what you're doing.