import re
regex = re.compile(r"^<{7} HEAD(?:\r?\n(?!={7}\r?\n).*)*\r?\n={7}(?:\r?\n(?!>{7} ).*)*\r?\n>{7} [a-z0-9]+", flags=re.MULTILINE)
test_str = ("<<<<<<< HEAD\n"
"$conf['some_unit_id'] = '4-qw-gg-ds-sometext';\n"
"=======\n"
"// Some Snippets Site Info\n"
"$conf['site_info'] = array(\n"
" 'customer_service_phone' => '+1 323223232\n"
" 'logo_path' => 'https://www.google.com/img/icons/src/logo.svg',\n"
" 'currency' => 'CAD',\n"
" 'https://www.youtube.com/user/somewebsite/ogog',\n"
" 'https://www.instagram.com/somewebsite/',\n"
" ),\n"
");\n"
">>>>>>> ff6df3435231fdff78fwsd83e7dffa0732eft554\n\n"
"// Somes code\n"
"$done['rules'] = TRUE;")
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