Roundup(I used a capital vowel to indicate where in the word the substitution should take place). Let me know if you want me to add other test strings.
import re
strings = [
'wE:aanyoh',
'hirU:atghigu',
'yO:ubeki',
'xE:aaa',
'xx:aaa',
'xa:aaaxA:aaa',
'xa:aaaxA:aaaxx',
'xa:aaaxA:aaxax',
'a:aaaxA:aaxax',
'e:aeixA:aexix',
]
pattern = r"""
(
.*
[aeiou]
)
:
(
[aeiou]
.*?
[aeiou]
.*?
[aeiou]
)
"""
template = "{:>15}: {}"
for string in strings:
print(
template.format('original', string)
)
print(template.format('Alexander:',
re.sub(ur"(?<=[aeiou]):(?=[aeiou]([^aeiou]*[aeiou]){2}[^aeiou]*$)", ur'', string, flags=re.I)
))
print(template.format('lonut:',
re.sub(ur"([aeiou]):([aeiou])([^\Waeiou]*[aeiou][^\Waeiou]*[aeiou][^\Waeiou]*)$", ur'\1\2\3', string, flags=re.I)
))
print(template.format('Tom Zych:',
re.sub(r'([^aeiou]*[aeiou][^aeiou]*):((?:[^aeiou]*[aeiou]){3}[^aeiou]*)$', r'\1\2', string, flags=re.I)
))
print(template.format('Jeff Y:',
re.sub(ur"([aeiou]):(([aeiou][^aeiou]*){3})$", ur'\1\2', string, flags=re.I)
))
print(template.format('7stud:',
re.sub(pattern, r'\1\2', string, count=1, flags=re.X|re.I)
))
print("\n")
original: wE:aanyoh
Alexander:: wEaanyoh
lonut:: wEaanyoh
Tom Zych:: wEaanyoh
Jeff Y:: wEaanyoh
7stud:: wEaanyoh
original: hirU:atghigu
Alexander:: hirUatghigu
lonut:: hirUatghigu
Tom Zych:: hirUatghigu
Jeff Y:: hirUatghigu
7stud:: hirUatghigu
original: yO:ubeki
Alexander:: yOubeki
lonut:: yOubeki
Tom Zych:: yOubeki
Jeff Y:: yOubeki
7stud:: yOubeki
original: xE:aaa
Alexander:: xEaaa
lonut:: xEaaa
Tom Zych:: xEaaa
Jeff Y:: xEaaa
7stud:: xEaaa
original: xx:aaa
Alexander:: xx:aaa
lonut:: xx:aaa
Tom Zych:: xx:aaa
Jeff Y:: xx:aaa
7stud:: xx:aaa
original: xa:aaaxA:aaa
Alexander:: xa:aaaxAaaa
lonut:: xa:aaaxAaaa
Tom Zych:: xa:aaaxAaaa
Jeff Y:: xa:aaaxAaaa
7stud:: xa:aaaxAaaa
original: xa:aaaxA:aaaxx
Alexander:: xa:aaaxAaaaxx
lonut:: xa:aaaxAaaaxx
Tom Zych:: xa:aaaxAaaaxx
Jeff Y:: xa:aaaxAaaaxx
7stud:: xa:aaaxAaaaxx
original: xa:aaaxA:aaxax
Alexander:: xa:aaaxAaaxax
lonut:: xa:aaaxAaaxax
Tom Zych:: xa:aaaxAaaxax
Jeff Y:: xa:aaaxAaaxax
7stud:: xa:aaaxAaaxax
original: a:aaaxA:aaxax
Alexander:: a:aaaxAaaxax
lonut:: a:aaaxAaaxax
Tom Zych:: a:aaaxAaaxax
Jeff Y:: a:aaaxAaaxax
7stud:: a:aaaxAaaxax
original: e:aeixA:aexix
Alexander:: e:aeixAaexix
lonut:: e:aeixAaexix
Tom Zych:: e:aeixAaexix
Jeff Y:: e:aeixAaexix
7stud:: e:aeixAaexix
wef:fewee? The colon is before the third-from-last vowel, there is a colon preceeding it, and there are two vowels later on. It satisfies your description, but not your code.