推荐学习书目
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 · 2444 views
    This topic created in 3981 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   ·   Solana   ·   1074 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 18:24 · PVG 02:24 · LAX 11:24 · JFK 14:24
    ♥ Do have faith in what you're doing.