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-05-23 15:48:14 +08:00 · 2872 次点击
    这是一个创建于 3998 天前的主题,其中的信息可能已经有所发展或是发生改变。
    https://gist.github.com/kenneth/5633351

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

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