On Apr 1, 1:38 pm, Rehceb Rotkiv <reh...@no.spam.plzwrote:
In the re documentation, it says that the matching functions return "non-
overlapping" matches only, but I also need overlapping ones. Does anyone
know how this can be done?
Perhaps lookahead assertions are what you're
looking for?
import re
import string
non_overlap = re.compile(r'[0-9a-fA-F]{2}')
pairs = [ match.group(0) for match in
non_overlap.finditer(string.hexdigits) ]
print pairs
overlap = re.compile(r'[0-9a-fA-F](?=([0-9a-fA-F]))')
pairs = [ match.group(0) + match.group(1) for match in
overlap.finditer(string.hexdigits) ]
print pairs
--
Hope this helps,
Steven