V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
thedevil7
V2EX  ›  Python

求教, 如何从一段输入中取出其中的数字?

  •  
  •   thedevil7 · Apr 25, 2012 · 3224 views
    This topic created in 5127 days ago, the information mentioned may be changed or developed.
    比如, 输入" 1, 2, 3 ,4, 11, 14, 16,av20,bc30" 所有的符号不要, 所有字母不要, 最后只要一个 list = [1, 2, 3, 4, 11, 14, 16, 20, 30].
    我现在可以做到用正则表达式剔除除了数字的部分, 得到一个字符串"1 2 3 4 11 14 16 20 30".
    p = re.compile(r'\D+')
    p.sub(" ", rawdata)
    但是不知道下一步怎么办了.
    1 replies    1970-01-01 08:00:00 +08:00
    thedevil7
        1
    thedevil7  
    OP
       Apr 25, 2012
    利用 [ int(i) for i in re.split(p, rawdata) ] 解决了.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3065 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 05:35 · PVG 13:35 · LAX 22:35 · JFK 01:35
    ♥ Do have faith in what you're doing.