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

求助,字符替换

  •  
  •   sparkssssssss · Oct 19, 2022 · 1711 views
    This topic created in 1297 days ago, the information mentioned may be changed or developed.
    <a href="http://127.0.0.1/<b>test1</b>"><b>test</b></a></br><a href="http://127.0.0.1/<b>test2</b><b>test2</b>"><b>test2</b></a></br><a href="http://127.0.0.1/<b>test3</b><b>test3</b><b>test3</b>">test3</a></br><b>thisistest1</b><b>thisistest2</b>


    如上 html 示例代码,想用正则替换掉<a href="http://127.0.0.1/<b>test1</b>"> 这种格式里面的<b>和</b>标签,用 re.sub,总是有点问题,要么删除的不干净,要么过了,把后面标签外的也去掉了.请大家帮忙看看,谢谢了!
    r6cb
        1
    r6cb  
       Oct 19, 2022
    给个思路:括号匹配
    sparkssssssss
        3
    sparkssssssss  
    OP
       Oct 20, 2022 via Android
    基本算解决了吧,先把 br 换成 /n ,之前正则总是误伤,
    这样,非贪婪匹配的时候就不会跨行误伤
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4078 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 05:08 · PVG 13:08 · LAX 22:08 · JFK 01:08
    ♥ Do have faith in what you're doing.