Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- дано:
- txt="""
- Port ID : 1:1
- --------------------------------------------------------------------
- Entity 2
- Chassis ID Subtype : macAddress
- Chassis ID : 00:1e:13:27:fc:b6
- Port ID Subtype : Interface Alias
- Port ID : Gi4/7
- Port Description : Link to S2-5-8
- System Name : S2-1-1.II.tomica.ru
- System Description : Cisco IOS Software, s72033_rp Softwar
- e (s72033_rp-ADVENTERPRISEK9_WAN-M),
- Version 12.2(33)SXI3, RELEASE SOFTWAR
- E (fc2)
- Technical Support: http://www.cisco.c
- om/t
- System Capabilities : Router
- Management Address : See Detail
- MAC/PHY Configuration/Status : See Detail
- Unknown TLVS : See Detail
- Port ID : 1:13
- --------------------------------------------------------------------
- Entity 1
- Chassis ID Subtype : macAddress
- Chassis ID : b8:af:67:68:11:a8
- Port ID Subtype : Interface Name
- Port ID : GigabitEthernet1/0/5
- Port Description : LAG_Tomica_Connect
- System Name : sw1-ln-tomsk-nts
- System Description : HP Comware Platform Software, Softwar
- e Version 5.20.99 Release 2220P02
- HP A5500-24G-SFP EI Switch with 2 Int
- erface Slots
- Copyright (c) 2010-2013 Hewlett-Packa
- System Capabilities : Bridge, Router
- Management Address : See Detail
- MAC/PHY Configuration/Status : See Detail
- Unknown TLVS : See Detail
- Port ID : 1:14
- --------------------------------------------------------------------
- Entity 3
- Chassis ID Subtype : macAddress
- Chassis ID : b8:af:67:68:11:a8
- Port ID Subtype : Interface Name
- Port ID : GigabitEthernet1/0/6
- Port Description : LAG_Tomica_Connect
- System Name : sw1-ln-tomsk-nts
- System Description : HP Comware Platform Software, Softwar
- e Version 5.20.99 Release 2220P02
- HP A5500-24G-SFP EI Switch with 2 Int
- erface Slots
- Copyright (c) 2010-2013 Hewlett-Packa
- System Capabilities : Bridge, Router
- Management Address : See Detail
- MAC/PHY Configuration/Status : See Detail
- Unknown TLVS : See Detail
- """
- Нужно выловить три блока текста, начиная с
- "Port ID : число:число
- --------------------------------------------------------------------
- Entity" до следующего такого шаблона или конца всего текста.
- Порт получаю:
- rx_port_id_group = re.compile(
- r"Port ID\s+:\s+(?P<port>(?:ch|\d+:)\d+)\s*(?:[-]{5,})\s*Entity\s*", re.IGNORECASE | re.MULTILINE | re.DOTALL)
- for match in rx_port_id_group.finditer(v):
- print match.group("port")
Advertisement
Add Comment
Please, Sign In to add comment