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

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

  •  
  •   forreal · 2014-06-21 16:27:46 +08:00 · 2881 次点击
    这是一个创建于 3610 天前的主题,其中的信息可能已经有所发展或是发生改变。
    用的是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 条回复    2014-06-21 17:48:03 +08:00
    forreal
        1
    forreal  
    OP
       2014-06-21 16:42:39 +08:00
    第二行代码改为
    regex = re.compile(r"<[^>]*>|[\u4e00-\u9fa5]|[a-zA-Z]*|\d*")
    还是取不到数字25
    czheo
        2
    czheo  
       2014-06-21 17:44:02 +08:00   ❤️ 1
    把所有的* 改成+ 试试
    forreal
        3
    forreal  
    OP
       2014-06-21 17:48:03 +08:00
    @czheo 哈哈,取到了,多谢。^_^
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1539 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:56 · PVG 07:56 · LAX 16:56 · JFK 19:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.