I wondered if there was such a thing, and when I looked it up, it was there, so make a note.
If you want to get more information than the matched text about what matches the pattern, finditer (), which returns an instance of MatchObject instead of a string, is useful. If you want to find out all the adverbs and their positions in some sentence, as shown in the example below, use finditer () as shown below. ::
>>> text = "He was carefully disguised but captured quickly by police."
>>> for m in re.finditer(r"\w+ly", text):
... print '%02d-%02d: %s' % (m.start(), m.end(), m.group(0))
07-16: carefully
40-47: quickly
For texts containing Japanese, use decode to convert to unicode.
text = "This is a test"
regex = "test"
a = re.finditer(regex.decode('utf8'), text.decode('utf8'))
for i in a: print i.group(), i.start(), i.end()
Result is,
Test 3 6