# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = 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 = re.finditer(regex, test_str)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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