#!/usr/bin/env python
#coding:utf-8
#
import re
ss = "07/10/2017 | 07:59:13 | Memory #0x08 | Correctable E"
pat = re.compile(r'((?P<date>\d+)/(?P<month>\d+)/(?P<year>\d+)\D+(?P<hour>\d+):(?P<minute>\d+):(?P<second>\d+)).*')
for x in pat.finditer(ss):
print(x.start())
print(x.groupdict().items())
# [('hour', '07'), ('month', '10'), ('second', '13'), ('year', '2017'), ('date', '07'), ('minute', '59')]
# example 2
text = "http://www.baidu.com/king/abc2333king/helloworld"
PATTERN = 'king'
for match in re.finditer(PATTERN, text):
s = match.start()
e = match.end()
print('Found {!r} at {:d}:{:d}'.format(text[s:e], s, e))