import re
regex = re.compile(r"(?P<bar>\+[+\-=]+\+)(?P<headline>.*?)(\+[+\-=]+\+)(?P<body>.*?)(\+[+\-=]+\+)", flags=re.MULTILINE | re.DOTALL)
test_str = ("+----+--------------------------------------+-------------+----------+--------+--------+--------------------+------------------+-------+-----------------+------------------------------+------------+-----------+--------------+------------+---------------------------------------------+---------------------+---------+\n"
"| No | ID | Name | VNFM | VIM | Tenant | VNF Package | Flavor | Level | Aspect | VNF Status | Job Status | Scale Opt | Scale Mode | Scale Unit | Workflow | Created At | Visible |\n"
"+----+--------------------------------------+-------------+----------+--------+--------+--------------------+------------------+-------+-----------------+------------------------------+------------+-----------+--------------+------------+---------------------------------------------+---------------------+---------+\n"
"| 0 | 0960ad53-bf7a-4c56-b980-cfa05a33fe71 | vzw_u13_cp3 | NSA_VNFM | simvim | vran | vzw_u13_cp3_i12i00 | VRAN-FLAVOR | 0 | SA_CPC=0 | vnf.instance.instantiate.end | COMPLETED | Enabled | Auto Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2021-01-12 04:35:51 | true |\n"
"| 1 | 33434187-2d82-48bd-9fd0-c67f2a8c9c87 | vzw_usm14 | NSA_VNFM | simvim | vsm | vzw21a_usm14 | VEMS-FLAVOR-TINY | 0 | AS_CF=0,AS_PS=0 | vnf.instance.instantiate.end | COMPLETED | Disabled | Manual Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2020-12-24 14:22:03 | true |\n"
"| 2 | 94b68ddb-06e6-45ae-a7dc-bf9204f61aa3 | vzw_usm12 | NSA_VNFM | simvim | vsm | vzw21a_usm12 | VEMS-FLAVOR-TINY | 0 | AS_CF=0,AS_PS=0 | vnf.instance.instantiate.end | COMPLETED | Disabled | Manual Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2020-12-24 13:15:55 | true |\n"
"| 3 | b60fdfff-c8d7-4656-bd77-d4621c1efbe5 | vzw_usm13 | NSA_VNFM | simvim | vsm | vzw21a_usm13 | VEMS-FLAVOR-TINY | 0 | AS_CF=0,AS_PS=0 | vnf.instance.instantiate.end | COMPLETED | Disabled | Manual Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2020-12-24 13:51:24 | true |\n"
"| 4 | c3de1762-57fb-4c0f-875e-e3b960629663 | vzw_u13_up3 | NSA_VNFM | simvim | vran | vzw_u13_up3_i12i00 | VRAN-FLAVOR | 0 | SA_UPC=0 | vnf.instance.instantiate.end | COMPLETED | Enabled | Auto Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2021-01-12 04:26:30 | true |\n"
"+----+--------------------------------------+-------------+----------+--------+--------+--------------------+------------------+-------+-----------------+------------------------------+------------+-----------+--------------+------------+---------------------------------------------+---------------------+---------+\n"
"item count : 5\n"
"[vnf-list] OK")
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