import re
regex = re.compile(r"(?<=\ id\ \|.)(([a-zA-Z0-9_]{8})-([a-zA-Z0-9_]{4})-([a-zA-Z0-9_]{4})-([a-zA-Z0-9_]{4})-([a-zA-Z0-9_]{12}))")
test_str = ("Created a new subnet: \n"
"+-------------------+------------------------------------------------+ \n"
"| Field | Value | \n"
"+-------------------+------------------------------------------------+ \n"
"| allocation_pools | {\"start\": \"10.42.42.2\", \"end\": \"10.42.42.254\"} | \n"
"| cidr | 10.42.42.0/24 | | dns_nameservers | | | enable_dhcp | True | \n"
"| gateway_ip | 10.42.42.1 | \n"
"| host_routes | | \n"
"| id | 3eded702-2909-4515-bf74-7c7c2c7c96e3 | \n"
"| ip_version | 4 | \n"
"| ipv6_address_mode | | \n"
"| ipv6_ra_mode | | \n"
"| name | Atelier | \n"
"| network_id | 5d15b14c-1d39-48d5-8f48-0dfd68c98d47 | \n"
"| tenant_id | d3c17d0e8bd742ed939794a98991886f \n"
"| +-------------------+------------------------------------------------+\n")
match = regex.search(test_str)
if match:
print(f"Match 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