import re
regex = re.compile(r"\w(?=\w{4})", flags=re.MULTILINE)
test_str = ("4f563a46jy7u35616\n"
"4f56sdfsddf\n"
"okmefiwmkiol\n"
"drejkskmilw\n"
"123434355454\n"
"34223")
subst = "#"
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