fork download
  1. import re
  2.  
  3. regex=r"^host-vpp1out .*(?:\r?\n[^\S\r\n]*L3 .*)*"
  4. test_str = ("VirtualFuncEthernet0/7/0.2001 (up):\n"
  5. " L3 1.1.2.2/24 ip4 table-id 8 fib-idx 2\n"
  6. " L3 2001:db8:0:1:1:1:2:2/112 ip6 table-id 8 fib-idx 1\n"
  7. "VirtualFuncEthernet0/9/0 (dn):\n"
  8. "host-vpp1out (up):\n"
  9. " L3 1.1.1.1/24\n"
  10. " L3 1.1.2.1/24\n"
  11. " L3 2001:db8:0:1:1:1:1:1/112\n"
  12. " L3 2001:db8:0:1:1:1:2:1/112\n"
  13. "local0 (dn):\n"
  14. "loop0 (up):\n"
  15. " L3 1.1.1.1/32 ip4 table-id 7 fib-idx 1")
  16.  
  17. match = re.search(regex, test_str, re.MULTILINE)
  18.  
  19. if match:
  20. print(re.findall(r" L3 (\d[\d.:\/a-z]+)\/\d+", match.group()))
Success #stdin #stdout 0.02s 9520KB
stdin
Standard input is empty
stdout
['1.1.1.1', '1.1.2.1', '2001:db8:0:1:1:1:1:1', '2001:db8:0:1:1:1:2:1']