推荐学习书目
› 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
ciba1990
V2EX  ›  Python

python 使用 re.sub 怎么转译'/'

  •  
  •   ciba1990 · Jul 13, 2015 · 2616 views
    This topic created in 4094 days ago, the information mentioned may be changed or developed.

    re.sub(r'/moon', '', url)
    我想把url中/moon替换成空,却无法实现,是不是‘/’在当中需要转译。

    2 replies  •  2015-07-14 08:42:17 +08:00
    MrEggNoodle
        1
    MrEggNoodle  
       Jul 13, 2015
    我运行成功了。
    >>> url = r'http://www.baidu.com/moon'
    >>> re.sub(r'/moon', '', url)
    'http://www.baidu.com'

    python里面的r就是真实字符,不转译了。
    msg7086
        2
    msg7086  
       Jul 14, 2015 via Android
    / 为啥要转义?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4914 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:16 · PVG 09:16 · LAX 18:16 · JFK 21:16
    ♥ Do have faith in what you're doing.