import re
regex = re.compile(r"\.(?=(.*)\b(?:19[2-9]|20[0-2])\d\b)", flags=re.MULTILINE)
test_str = ("This.Is.The.Movie.Title.1930.details.of\n"
"This.Is.The.Movie.Title.2013.details\n\n"
"This.Is.The.Movie.Title.1919.details.of (year too early)\n"
"This.Is.The.Movie.Title.2030.details.of (year too late)\n"
"This.Is.The.Movie.Title.201.details.of (too few year digits)\n"
"This.Is.The.Movie.Title.20000.details.of (too many year digits)\n")
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