import re
regex = re.compile(r"(?m)^NAME=\"(?P<name>(?P<disk>[a-z]+)(?P<partition>\d*))\"\sFSTYPE=\"(?P<fstype>\w*)\"\sMOUNTPOINT=\"(?P<mountpoint>[\w\[\]/]*)\"\sSIZE=\"(?P<size>\d*)\"\sTYPE=\"(?P<type>\w+)\"$", flags=re.MULTILINE)
test_str = ("NAME=\"loop0\" FSTYPE=\"LVM2_member\" MOUNTPOINT=\"\" SIZE=\"20971520000\" TYPE=\"loop\"\n"
"NAME=\"sda\" FSTYPE=\"\" MOUNTPOINT=\"\" SIZE=\"171798691840\" TYPE=\"disk\"\n"
"NAME=\"sda1\" FSTYPE=\"ext4\" MOUNTPOINT=\"/boot\" SIZE=\"1073741824\" TYPE=\"part\"\n"
"NAME=\"sda2\" FSTYPE=\"LVM2_member\" MOUNTPOINT=\"\" SIZE=\"170723901440\" TYPE=\"part\"\n"
"NAME=\"sdb\" FSTYPE=\"\" MOUNTPOINT=\"\" SIZE=\"32212254720\" TYPE=\"disk\"\n"
"NAME=\"sdb1\" FSTYPE=\"LVM2_member\" MOUNTPOINT=\"\" SIZE=\"32211206144\" TYPE=\"part\"\n"
"NAME=\"sdc\" FSTYPE=\"\" MOUNTPOINT=\"\" SIZE=\"53687091200\" TYPE=\"disk\"\n"
"NAME=\"sdc1\" FSTYPE=\"LVM2_member\" MOUNTPOINT=\"\" SIZE=\"53686042624\" TYPE=\"part\"\n"
"NAME=\"sr0\" FSTYPE=\"\" MOUNTPOINT=\"\" SIZE=\"1073741312\" TYPE=\"rom\"\n"
"NAME=\"cl_ctos8auto-root\" FSTYPE=\"xfs\" MOUNTPOINT=\"/\" SIZE=\"106300440576\" TYPE=\"lvm\"\n"
"NAME=\"cl_ctos8auto-root\" FSTYPE=\"xfs\" MOUNTPOINT=\"/\" SIZE=\"106300440576\" TYPE=\"lvm\"\n"
"NAME=\"cl_ctos8auto-swap\" FSTYPE=\"swap\" MOUNTPOINT=\"[SWAP]\" SIZE=\"8497659904\" TYPE=\"lvm\"\n"
"NAME=\"cl_ctos8auto-home\" FSTYPE=\"xfs\" MOUNTPOINT=\"/home\" SIZE=\"108536004608\" TYPE=\"lvm\"\n"
"NAME=\"cl_ctos8auto-var_log\" FSTYPE=\"ext4\" MOUNTPOINT=\"/opt/imsdb/chroot-sybase/var/log\" SIZE=\"32208060416\" TYPE=\"lvm\"\n"
"NAME=\"b38ad718--fc07--11ea--9894--0050569ae644-fea1a18c--fc07--11ea--9894--0050569ae644\" FSTYPE=\"ext4\" MOUNTPOINT=\"/opt/intelerad/atlas/1/storage/b30f29df-8fc2-4db5-8c17-4275cdae6b3f\" SIZE=\"20967325696\" TYPE=\"lvm\"")
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