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

python3 中关于一个正则表达式的问题

  •  
  •   forreal · Jun 21, 2014 · 3822 views
    This topic created in 4484 days ago, the information mentioned may be changed or developed.
    用的是python3.3.5 IDE是pycharm
    我想取出标签、汉字、单词、数字、和空格
    代码如下
    import re
    regex = re.compile("<[^>]*>|[\u4e00-\u9fa5]|[a-zA-Z]*|\d*|\s*")
    print(regex.findall('''<i> bob是</i>25岁<br/>'''))

    结果是
    ['<i>', '', 'bob', '是', '</i>', '', '', '岁', '<br/>', '']
    想请教一下为什么数字25取不出来?
    3 replies  •  2014-06-21 17:48:03 +08:00
    forreal
        1
    forreal  
    OP
       Jun 21, 2014
    第二行代码改为
    regex = re.compile(r"<[^>]*>|[\u4e00-\u9fa5]|[a-zA-Z]*|\d*")
    还是取不到数字25
    czheo
        2
    czheo  
       Jun 21, 2014   ❤️ 1
    把所有的* 改成+ 试试
    forreal
        3
    forreal  
    OP
       Jun 21, 2014
    @czheo 哈哈,取到了,多谢。^_^
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2589 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:25 · PVG 22:25 · LAX 07:25 · JFK 10:25
    ♥ Do have faith in what you're doing.