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

u"语 82.5 数 98.5 外 90", 正则表达式问题, 没有空格哈,空格是 v2 加的

  •  
  •   thinker3 · Aug 21, 2016 · 2828 views
    This topic created in 3542 days ago, the information mentioned may be changed or developed.
    最多只有语数外三科
    u"语 82.5 数 98.5 外 90"
    u"语 82.5 外 96"
    提取成 dict
    6 replies    2016-08-22 17:17:40 +08:00
    billlee
        1
    billlee  
       Aug 21, 2016
    dict(re.findall(u"(.?)([0-9.]+)", data))
    billlee
        2
    billlee  
       Aug 21, 2016
    一时手抖多了个?, 应该是 (.)([0-9.]+)
    tttimit
        3
    tttimit  
       Aug 22, 2016 via Android
    r'([语|数|外](1?\d?\d.?5?))'手机打字不易 一个模式就是这样,匹配语文或者数学或者外语加上成绩,成绩可以是带.5 的,来三遍,第二科第三科照我写的来就行,最后用 groups 取值,写好前后加^$。
    tttimit
        4
    tttimit  
       Aug 22, 2016 via Android
    第一个方括号去掉里面的两条竖线。。
    ioiogoo
        5
    ioiogoo  
       Aug 22, 2016
    如果格式严谨的话
    ```
    string = u"语 82.5 数 98.5 外 90".split(' ')
    {string[x]:string[x+1] for x in range(string) if x%2 == 0}
    ```
    sparkssssssss
        6
    sparkssssssss  
       Aug 22, 2016
    新人练手
    data = u"语 82.5 数 98.5 外 90"
    res = re.findall('(.*?)(\d+(\.\d+)?)',data)
    dict = {}
    for i in res:
    dict[i[0]] = i[1]
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   998 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 17:59 · PVG 01:59 · LAX 10:59 · JFK 13:59
    ♥ Do have faith in what you're doing.