import re p = re.compile(r'\b(?!(?:18|19|20)\d{2}\b)\d+\b') test_str = "Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network, 4 5 6 created in 2008" print p.sub("", test_str)
Standard input is empty
Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network, created in 2008