import re a = '11223344 55667788 generic_name 99001122 334455 generic_name 4444555 66667777' p1 = re.compile(r'[0-9]+') p2 = re.compile(r'generic_name') r1 = p1.finditer(a) r2 = p2.finditer(a) result = [] i = 0 print 'spans for numbers' for each in r1: print each.span() i = i + 1 i = 0 print 'spans for -generic_name' for each in r2: print each.span()[0] print each.span()[1] - each.span()[0] i = i + 1
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question