python的正则表达式入门求助 - V2EX
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 Guie
Code Style from The Hitchhiker's Guide
lucker6666

python的正则表达式入门求助

  •  
      lucker6666 2013 年 11 月 18 日 4594 次点击
    这是一个创建于 4541 天前的主题,其中的信息可能已经有所发展或是发生改变。
    初学python 遇到正则表达式的难题 各位大虾能推荐下如何入门么

    http://*259

    诸如此类网址末尾是数字 怎么把它从网页里提取出来?
    第 1 条附言    2013 年 11 月 19 日
    谢谢各位的帮助 有点心得了
    10 条回复    1970-01-01 08:00:00 +08:00
    yxjxx
        2
    yxjxx  
       2013 年 11 月 18 日   1
    我也刚学python不久,写过一篇笔记. http://yxjxx.me/regular-expression
    mengzhuo
        3
    mengzhuo  
       2013 年 11 月 18 日   1
    首先网页就不要用正则提取内容,BS4是你的好伙伴
    然后提取的所有链接再用正则匹配

    https?:\/\/([\d\.]+)\/
    Perry
        4
    Perry  
       2013 年 11 月 19 日   1
    关于入门:
    入门正则可以不用书
    几分钟的入门:http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/
    cheatsheet:http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/
    然后发挥你的想象力自己写并验证:http://rubular.com
    LetFoxRun
        5
    LetFoxRun  
       2013 年 11 月 19 日 via Android   1
    @yxjxx

    博客里的 intersting 是不是打错了,还是故意这么写的?
    sandtears
        6
    sandtears  
       2013 年 11 月 19 日   1
    import re
    tmpRe = re.compile(r"^http://.*?(\d+)$")
    tmpNum = tmpRe.match(url).groups()[0]

    此时tmp即为str类型的数字
    clino
        7
    clino  
       2013 年 11 月 19 日   1
    建议装一个 kodos ,是一个正则的调试集成环境
    lixm
        8
    lixm  
       2013 年 11 月 19 日
    html页面为什么不用xml解析而要去用正则呢?
    yxjxx
        9
    yxjxx  
       2013 年 11 月 19 日
    @LetFoxRun ,打错了!感谢指出!
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2819 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 54ms UTC 09:36 PVG 17:36 LAX 02:36 JFK 05:36
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86