Home

Tags

regexp finditer в python

2010-04-23 python regexp

Пример использования finditer

import re
d = re.finditer(r'(?P<word>\w+)', 'Hello world, this system nipil')
for i in d:
    print i.start(),i.end(),i.group(),i.groups(),i.span(),i.groupdict()

Результат
0 5 Hello ('Hello',) (0, 5) {'word': 'Hello'}
6 11 world ('world',) (6, 11) {'word': 'world'}
13 17 this ('this',) (13, 17) {'word': 'this'}
18 24 system ('system',) (18, 24) {'word': 'system'}
25 30 nipil ('nipil',) (25, 30) {'word': 'nipil'}


см. regexp методы в python

comments powered by Disqus