import re
regex = re.compile(r"^(?<atributo>(?<pai>(?:[^=.\n]+)\.?){1,6})=(?<valor>(?:[^=\n]+))$", flags=re.DOTALL | re.MULTILINE)
test_str = ("php.environment.ini.session-name = sisicmbio\n"
"php.environment.ini.session-cookie_domain = icmbio.gov.br\n"
"php.environment.ini.session-auto_start = false\n"
"php.environment.ini.session-cookie_path = /\n"
"php.environment.ini.session-cookie_lifetime = 10800\n"
"php.environment.ini.session-cookie_httponly = true\n"
"php.environment.ini.session-use_only_cookie = true\n"
"php.environment.ini.session-gc_maxlifetime = 10800\n"
"php.environment.ini.session-cache_expire = 180\n\n"
";; [php server mail]\n"
"php.mail.sender = smtp\n"
"php.mail.from = notifica@domain.gov.br ; conta default usada para enviar mensagens\n"
"php.mail.replyTo = reposta@domain.gov.br ; conta usada para reply\n"
"php.mail.wordWrap = 60\n"
"php.mail.priority = 3 ; 1: high, 3: normal, 5: low\n"
"php.mail.encoding = 8bit ; 8bit, 7bit, binary, base64, quoted-printable\n"
"php.mail.charset = utf-8\n"
"php.mail.contentType = text/html")
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