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

python 正则表达式的问题

  •  
  •   Alpha ·
    alphachoi · 2011-04-30 14:12:58 +08:00 · 4489 次点击
    这是一个创建于 4716 天前的主题,其中的信息可能已经有所发展或是发生改变。
    str = 'var html = new Array("a","b","c"); var text = "(new python book)";'
    如何将字符串 ("a","b","c")匹配出来?

    我的思路是想这样,但语法肯定不对,这其中的小括号怎么转义或匹配?
    p = re.compile(r"(?+)?")

    print p.match(str).group()
    1 条回复    1970-01-01 08:00:00 +08:00
    aligo
        1
    aligo  
       2011-04-30 14:49:38 +08:00
    re.findall("(\(.+?\))", str)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3301 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 00:40 · PVG 08:40 · LAX 17:40 · JFK 20:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.