I would split string to words and process word with function. For replacement I would use str.translate. Assuming that this is text in english:
import string s = "Masonry - Concrete Block (Small) - Misc Air Layer - Insulation - Aluminium" def process(word): mapping = str.maketrans(dict.fromkeys('aeiou', '')) length = 0 for char in word: if char in string.ascii_letters: length += 1 if 4 < length: return word.translate(mapping) else: # no-break return word print(' '.join(process(word) for word in s.split())) # -> Msnry - Cncrt Blck (Smll) - Misc Air Lyr - Insltn - Almnm
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.