import re
regex = re.compile(r"(?i)(\s*)(|\"|')(name|phoneNumber|race|gender|birthdate|geodata)(|\"|')(\s*)(:|=)(\s*)('|\"|\s*)(\s*)(^$|.*?)(\s*)('|,|\"|\))", flags=re.MULTILINE)
test_str = ("\"username\":\"username\"\n"
"\"phonenumber\":\"123 456 7890\"\n"
"\"race\":\"undisclosed\"\n"
"\"gender\":\"female\"\n"
"\"birthdate\":\"03/12/1889\"\n"
"\"geodata\":\"123 456 7890\"\n"
"\"phonenumber\":\"123 456 7890\"\n"
"\"geodata\":\"38.897957\"")
subst = "$1$2$3$4$5$6$7$8$9*******$11$12"
result = regex.sub(subst, test_str)
if result:
print(result)
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