Guest User

TSergey, 2014-09-11, regexp

a guest
Sep 11th, 2014
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. дано:
  2. txt="""
  3. Port ID : 1:1
  4. --------------------------------------------------------------------
  5.  
  6. Entity 2
  7. Chassis ID Subtype : macAddress
  8. Chassis ID : 00:1e:13:27:fc:b6
  9. Port ID Subtype : Interface Alias
  10. Port ID : Gi4/7
  11. Port Description : Link to S2-5-8
  12. System Name : S2-1-1.II.tomica.ru
  13. System Description : Cisco IOS Software, s72033_rp Softwar
  14. e (s72033_rp-ADVENTERPRISEK9_WAN-M),
  15. Version 12.2(33)SXI3, RELEASE SOFTWAR
  16. E (fc2)
  17. Technical Support: http://www.cisco.c
  18. om/t
  19. System Capabilities : Router
  20. Management Address : See Detail
  21. MAC/PHY Configuration/Status : See Detail
  22. Unknown TLVS : See Detail
  23.  
  24. Port ID : 1:13
  25. --------------------------------------------------------------------
  26.  
  27. Entity 1
  28. Chassis ID Subtype : macAddress
  29. Chassis ID : b8:af:67:68:11:a8
  30. Port ID Subtype : Interface Name
  31. Port ID : GigabitEthernet1/0/5
  32. Port Description : LAG_Tomica_Connect
  33. System Name : sw1-ln-tomsk-nts
  34. System Description : HP Comware Platform Software, Softwar
  35. e Version 5.20.99 Release 2220P02
  36. HP A5500-24G-SFP EI Switch with 2 Int
  37. erface Slots
  38. Copyright (c) 2010-2013 Hewlett-Packa
  39. System Capabilities : Bridge, Router
  40. Management Address : See Detail
  41. MAC/PHY Configuration/Status : See Detail
  42. Unknown TLVS : See Detail
  43.  
  44. Port ID : 1:14
  45. --------------------------------------------------------------------
  46.  
  47. Entity 3
  48. Chassis ID Subtype : macAddress
  49. Chassis ID : b8:af:67:68:11:a8
  50. Port ID Subtype : Interface Name
  51. Port ID : GigabitEthernet1/0/6
  52. Port Description : LAG_Tomica_Connect
  53. System Name : sw1-ln-tomsk-nts
  54. System Description : HP Comware Platform Software, Softwar
  55. e Version 5.20.99 Release 2220P02
  56. HP A5500-24G-SFP EI Switch with 2 Int
  57. erface Slots
  58. Copyright (c) 2010-2013 Hewlett-Packa
  59. System Capabilities : Bridge, Router
  60. Management Address : See Detail
  61. MAC/PHY Configuration/Status : See Detail
  62. Unknown TLVS : See Detail
  63. """
  64. Нужно выловить три блока текста, начиная с
  65. "Port ID : число:число
  66. --------------------------------------------------------------------
  67.  
  68. Entity" до следующего такого шаблона или конца всего текста.
  69.  
  70.  
  71. Порт получаю:
  72. rx_port_id_group = re.compile(
  73. r"Port ID\s+:\s+(?P<port>(?:ch|\d+:)\d+)\s*(?:[-]{5,})\s*Entity\s*", re.IGNORECASE | re.MULTILINE | re.DOTALL)
  74. for match in rx_port_id_group.finditer(v):
  75. print match.group("port")
Advertisement
Add Comment
Please, Sign In to add comment