我想解析uptimeUnix 命令的输出。这是两个不同的样本:
14:25  up 1 day,  1:24, 2 users, load averages: 0,56 0,48 0,47
14:25  up 1:24, 2 users, load averages: 0,56 0,48 0,47
(我使用的语言是 Python)
所以,假设上面的两个样本被保存到变量s1和s2.
这是我写的代码:
>>> RE = r'''
    ((\d) \s day)?        # this should match "n day" if it's there 
    .*?                   # this should match everything until the next regex
    \s(\d{1,2}):(\d{1,2}) # this should match a space followed by "hh:mm"
'''
>>> print re.match(RE, s1, re.VERBOSE).groups()
(None, None, '1', '24')
>>> print re.match(RE, s2, re.VERBOSE).groups()
(None, None, '1', '24')
正则表达式的第二部分,即抓住正常运行时间的几小时-分钟的部分,完美运行。但是为什么元组的第一部分总是None?我错过了什么?这是一个贪婪与非贪婪的问题吗?