import re
day = r'(?:((?:0?[1-9]|[12]\d|3[01])(?:\s*(?:st|[rn]d|th))?)\s*)?'
month = r'(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t(?:ember)?)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)'
year = r'(\d{2}(?:\d{2})?)'
rx_valid = re.compile( fr'\b{day}{month}\s*{year}\s*[-—–]\s*{day}{month}\s*{year}(?!\d)', re.IGNORECASE )
rx_ordinal = re.compile( r'\s*\d+\s*(?:st|[rn]d|th)', re.IGNORECASE )
lst = [
'July 2014 - 28th August 2014',
'Jan 2012 - 3rd sep 2014',
'Jan 2008 - May 2012',
'Jan 2008 and May 2012'
]
for i in lst:
word = rx_valid.finditer(i)
for match in word:
print(rx_ordinal.sub("", match.group()))
aW1wb3J0IHJlCgoKZGF5ID0gcicoPzooKD86MD9bMS05XXxbMTJdXGR8M1swMV0pKD86XHMqKD86c3R8W3JuXWR8dGgpKT8pXHMqKT8nCm1vbnRoID0gcicoSmFuKD86dWFyeSk/fEZlYig/OnJ1YXJ5KT98TWFyKD86Y2gpP3xBcHIoPzppbCk/fE1heXxKdW5lP3xKdWx5P3xBdWcoPzp1c3QpP3xTZXAoPzp0KD86ZW1iZXIpPyk/fE9jdCg/Om9iZXIpP3xOb3YoPzplbWJlcik/fERlYyg/OmVtYmVyKT8pJyAKeWVhciA9IHInKFxkezJ9KD86XGR7Mn0pPyknCnJ4X3ZhbGlkID0gcmUuY29tcGlsZSggZnInXGJ7ZGF5fXttb250aH1ccyp7eWVhcn1ccypbLeKAlOKAk11ccyp7ZGF5fXttb250aH1ccyp7eWVhcn0oPyFcZCknLCByZS5JR05PUkVDQVNFICkKcnhfb3JkaW5hbCA9IHJlLmNvbXBpbGUoIHInXHMqXGQrXHMqKD86c3R8W3JuXWR8dGgpJywgcmUuSUdOT1JFQ0FTRSApCgpsc3QgPSBbCiAgICAnSnVseSAyMDE0IC0gMjh0aCBBdWd1c3QgMjAxNCcsCiAgICAnSmFuIDIwMTIgLSAzcmQgc2VwIDIwMTQnLAogICAgJ0phbiAyMDA4IC0gTWF5IDIwMTInLAogICAgJ0phbiAyMDA4IGFuZCBNYXkgMjAxMicKXQpmb3IgaSBpbiBsc3Q6CiAgICB3b3JkID0gcnhfdmFsaWQuZmluZGl0ZXIoaSkKICAgIGZvciBtYXRjaCBpbiB3b3JkOgogICAgICAgIHByaW50KHJ4X29yZGluYWwuc3ViKCIiLCBtYXRjaC5ncm91cCgpKSk=