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

菜鸟请教一个Python正则问题

  •  
  •   kenneth · 2013 年 5 月 23 日 · 3295 次点击
    这是一个创建于 4616 天前的主题,其中的信息可能已经有所发展或是发生改变。
    https://gist.github.com/kenneth/5633351

    想去掉content中的ubb,只要链接,应该如何写?

    请高手赐教。
    9 条回复    1970-01-01 08:00:00 +08:00
    jason52
        1
    jason52  
       2013 年 5 月 23 日
    您是想抓图?哪里有ubb呢?
    jason52
        2
    jason52  
       2013 年 5 月 23 日
    you mean URL?
    dreampuf
        4
    dreampuf  
       2013 年 5 月 23 日   ❤️ 1
    dreampuf
        5
    dreampuf  
       2013 年 5 月 23 日
    import re
    re.search("\\[(?:([^=]+)=([^\\]]+)|([^\\]]+))\\]([^\\[]+)\\[/(?:\\1|\\3)\\]", searchText)
    KotiyaSanae
        7
    KotiyaSanae  
       2013 年 5 月 23 日
    @kenneth 没太看懂你要匹配什么,是所有的boston么?那个网站不太会用……
    pattern = r'.*](http://.*html?).*' ? python环境下通过……
    jason52
        8
    jason52  
       2013 年 5 月 23 日
    这种事强烈推荐用pyquery做 代码可以很简单 抓图代码就这么一点
    http://dpaste.com/1196576/
    jason52
        9
    jason52  
       2013 年 5 月 23 日
    @KotiyaSanae 如果用re的话这种可以
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2361 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 15:55 · PVG 23:55 · LAX 07:55 · JFK 10:55
    ♥ Do have faith in what you're doing.