This will replace 'ABC' with 'bueno'only if it is not followed by '.png' or ' thumb.png'.
import re
texto = "ABC ABC. ABC.png ABC thumb\.png"
regex = r"\bABC\b(?!\.png|\s?thumb.png)"
novo = re.sub(regex, "bueno", texto)
print(novo)
RESULT:
bueno bueno. ABC.png ABC thumb.png