, ; :
for host in f:
match = re_hostinfo.search(host)
if match:
print match.groups()
host , .
:
data = f.read()
for x in regex.finditer(data):
process(x.groups())
regex - , .
, , , , , , . , , , , pyparsing.
, , :
MULTILINE; . , :
(1)
(2)
(3)
, .
:
>>> m = re.search(r'(hardware ethernet\s+(\S+));\s+\S+\s+(\S+);', data)
>>> print m.groups()
('hardware ethernet 00:22:38:8f:1f:43', '00:22:38:8f:1f:43', 'node20007.domain.com')
>>>
, " "... ,
, , . :
>>> regex = re.compile(r"""
... (hardware[ ]ethernet \s+
... (\S+) # MAC
... ) ;
... \s+ # includes newline
... \S+ # variable(??) text e.g. "fixed-address"
... \s+
... (\S+) # e.g. "node20007.domain.com"
... ;
... """, re.VERBOSE)
>>> print regex.search(data).groups()
('hardware ethernet 00:22:38:8f:1f:43', '00:22:38:8f:1f:43', 'node20007.domain.com')
>>>