import re
regex = re.compile(r"(?P<headers>.*)[\r\n][\r\n](?P<content>.*)", flags=re.MULTILINE | re.IGNORECASE | re.DOTALL)
test_str = ("------WebKitFormBoundary3JCHTJWwvnOcvnSv\n"
"Content-Disposition: form-data; name=\"_format\"\n\n"
"json\n"
"------WebKitFormBoundary3JCHTJWwvnOcvnSv\n"
"Content-Disposition: form-data; name=\"rid\"\n\n"
"1\n"
"------WebKitFormBoundary3JCHTJWwvnOcvnSv\n"
"Content-Disposition: form-data; name=\"avatar\"; filename=\"carlingford.jpg\"\n"
"Content-Type: image/jpeg\n\n\n"
"���p�� \n"
"��T!1\"AQa2q�#B�� R�$3b�C���%r�4S�&�5c\n"
"Ds��'ET�d6U��� ��L!1AQaq\"��2����#��BR�b$3r����C%4S��s�&5DTc���?�g������F΅%v9��Ge�9�С@#B�'�y�4!p|hPW%<�8�:n��9�hI�B;�Ж�:R{�8Ћ(�m�:m�*����0��vƄ#��?'B���BQ����BGo}\n"
";#�a#�΄U��W�x?�E��H��:��#Ռ�t�L�6C�u ��#�R����22����n�c���B�@3ƅ\"��ZRN�dv΄�����Д��pB��'B]�rҥ�����Q���)P�� �R�����R9Y�I&��� =���X?�bI�u��ĮQ���!C�'dn�}��-n�s�j8 �c$����Q����$�q��� �@�J9$ryԁj�pN�9���B8+*��v�Sih�J}[�W��ґ���R�r�?��h�I�J!�P�?J��+��T���+��Q�)�m\n"
"od")
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