I'm trying to get the offset of the match found using re.search().
http://docs.python.org/dev/howto/regex.html
This site explains how to get offsets of match components relative to the start of the match, but doesn't say how to get the offset of the match itself in the "haystack" string.
>>> import re
>>> s = 'Hello, this is a string'
>>> m = re.search(',\s[a-z]',s)
>>> m.group()
', t'
>>> m.start()
5
More info can be found here.
You need to do something like this:
import re
for m in re.compile("[a-z]").finditer('what1is2'):
print m.start(), m.group()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With