Вы можете сделать это в одном регулярном выражении:
>>> reobj = re.compile("(?:auto|allow-|iface)(?:(?!(?:auto|allow-|iface)).)*(?<!\s)", re.DOTALL)
>>> result = reobj.findall(subject)
>>> result
['auto lo eth0', 'allow-hotplug eth1', 'iface eth0-home inet static\n address 192.168.1.1\n netmask 255.255.255.0']
Объяснение:
(?:auto|allow-|iface) # Match one of the search terms
(?: # Try to match...
(?! # (as long as we're not at the start of
(?:auto|allow-|iface) # the next search term):
) #
. # any character.
)* # Do this any number of times.
(?<!\s) # Assert that the match doesn't end in whitespace
Конечно, вы также можете отобразить результаты в списоккортежи в соответствии с вашим комментарием:
>>> reobj = re.compile("(auto|allow-|iface)\s*((?:(?!(?:auto|allow-|iface)).)*)(?<!\s)", re.DOTALL)
>>> result = [tuple(match.groups()) for match in reobj.finditer(subject)]
>>> result
[('auto', 'lo eth0'), ('allow-', 'hotplug eth1'), ('iface', 'eth0-home inet static\n address 192.168.1.1\n netmask 255.255.255.0')]