所以我有一個模式:Python的簡單的regex
hourPattern = re.compile('\d{2}:\d{2}')
而且對陣編譯模式
hourStart = hourPattern.match('Sat Jan 28 01:15:00 GMT 2012')
當我打印hourStart
它給了我無。任何幫助?
所以我有一個模式:Python的簡單的regex
hourPattern = re.compile('\d{2}:\d{2}')
而且對陣編譯模式
hourStart = hourPattern.match('Sat Jan 28 01:15:00 GMT 2012')
當我打印hourStart
它給了我無。任何幫助?
匹配期望找到的值位於字符串的開頭。你想要搜索。從比賽方法
>>> import re
>>>
>>> s = re.compile('\d+')
>>>
>>> s2 = 'a123'
>>>
>>> s.match(s2)
>>> s.search(s2)
<_sre.SRE_Match object at 0x01E29AD8>
切換到搜索方法:
>>> hourPattern = re.compile('\d{2}:\d{2}')
>>> hourStart = hourPattern.search('Sat Jan 28 01:15:00 GMT 2012')
>>> hourStart.group()
'01:15'
感謝您的幫助! – Jirico
明白了,謝謝傢伙! – Jirico
@Jirico - 樂於助人。請務必將答案標記爲已接受,以便其他用戶知道您已收到您所需的幫助。 :) –
好的男人,我是一個新手,但我得到它! – Jirico