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

Python 替换字符串的问题

  •  
  •   c00WKmdje2wZLrSI · Sep 28, 2018 · 2504 views
    This topic created in 2973 days ago, the information mentioned may be changed or developed.
    比如这样一段字符串
    <meta name="detectify-verification" content="d0264f228155c7a1f72c3d91c17ce8fb" />
    <meta name="p:domain_verify" content="b87e3b55b409494aab88c1610b05a5f0"/>
    <meta name="alexaVerifyID" content="OFc8dmwZo7ttU4UCnDh1rKDtLlY" />
    <meta name="baidu-site-verification" content="D00WizvYyr" />

    content 里面的内容是随机的,如何把他们替换成
    <meta name="detectify-verification" content="d0264f228155c7a1f72c3d91c17ce8fb.html" />
    <meta name="p:domain_verify" content="b87e3b55b409494aab88c1610b05a5f0.html"/>
    <meta name="alexaVerifyID" content="OFc8dmwZo7ttU4UCnDh1rKDtLlY.html" />
    <meta name="baidu-site-verification" content="D00WizvYyr.html" />

    我只懂得把 content 的内容提取出来,再 for 循环一个个替换,但是感觉有点麻烦,有没有办法不使用循环,直接用 replace 或者 re 搞定?
    zhzer
    zhzer
    Sep 28, 2018 via Android
    1
    过于基础了吧,建议百度,现在给你写了下次还要问
    imn1
    imn1
    Sep 28, 2018
    2
    同意#1
    不就把
    " />
    替换成
    .html" />
    ?

    你不会从来没用过替换方法吧?
    luckybo
    luckybo
    Sep 28, 2018
    3
    不就是 content=""里面的字符串+‘.html ’么😓
    c00WKmdje2wZLrSI
    c00WKmdje2wZLrSI
    OP
    Sep 28, 2018
    4
    @zhzer
    @imn1
    不是,感觉我问的方式有问题,这种问法的确一替换就好了,我再想想怎么问好
    Raisu
    Raisu
    Sep 28, 2018
    5
    这。。。。。。建议多做一些处理字符串的练习
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   933 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 21:54 · PVG 05:54 · LAX 13:54 · JFK 16:54
    ♥ Do have faith in what you're doing.