import re
regex = re.compile(r"(?ms)(RPA\s1:).+?Initiator\sID:\s(?<RPA1Initiator>[^ ]*)")
test_str = ("SITE_VPLEX: \n"
" RPAs: \n"
" RPA 1: \n"
" Version: 4.1.SP1.P1(h.167)\n"
" WAN IP: 000.000.000.000\n"
" RPA LAN IPv4: 000.000.000.000\n"
" RPA LAN IPv6:N/A\n"
" iSCSI interface IPs: None\n"
" Interfaces: \n"
" Type: FC\n"
" Initiator ID: 50012481006bexxx\n"
" Type: FC\n"
" Initiator ID: 50012481006bexxx\n"
" Type: FC\n"
" Initiator ID: 50012481006bexxx\n"
" Type: FC\n"
" Initiator ID: 50012481006bexxx\n"
" Hardware details: \n"
" Hardware type: Intel Corporation S2600GZ GEN5\n"
" Adapter type: 2564\n"
" Vendor: Intel Corporation\n"
" Hardware Serial ID: FC6RP133000229_00000000002_FFF\n"
" Hardware Platform: Intel Corporation S2600GZ GEN5\n"
" Amount of memory: 16269416 KB\n"
" Number of CPUs: 12\n"
" RPA 2: \n"
" Version: 4.1.SP1.P1(h.167)\n"
" WAN IP: 000.000.000.000\n"
" RPA LAN IPv4: 000.000.000.000\n"
" RPA LAN IPv6:N/A\n"
" iSCSI interface IPs: None\n"
" Interfaces: \n"
" Type: FC\n"
" Initiator ID: 50012481006bdxxx\n"
" Type: FC\n"
" Initiator ID: 50012481006bdxxx\n"
" Type: FC\n"
" Initiator ID: 50012481006bdxxx\n"
" Type: FC\n"
" Initiator ID: 50012481006bdxxx\n"
" Hardware details: \n"
" Hardware type: Intel Corporation S2600GZ GEN5\n"
" Adapter type: 2564\n"
" Vendor: Intel Corporation\n"
" Hardware Serial ID: FC6RP133000135_0000000000_FFF\n"
" Hardware Platform: Intel Corporation S2600GZ GEN5\n"
" Amount of memory: 16269416 KB\n"
" Number of CPUs: 12")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html