As you said you "need a regex", I thought to present only the regex "pure", without worrying about the language, but I would have to test it somehow, so I developed in python (I have this regex here in my "Knowledge Base" for years, it is not my own)I think it will be easy for you to pour into the.
Regex
regex = (?=[b-df-hj-np-tv-xz])(.)(?!\1)(?<!\1\1)
Explaining the parts:
(?=[b-df-hj-np-tv-xz]) Casa somente com consoantes
(.) A "gula" na regex, considera todas.
(?!\1) e (?<!\1\1) Evita duplicidade no final
Python implementation:
See the code execution in repl.it.
import re
var = 'algoritmo'
r1 = r'(?=[b-df-hj-np-tv-xz])(.)(?!\1)(?<!\1\1)'
result = re.findall(r1, var)
consonants = ''.join(str(e) for e in result)
print (consonants.split(' ')[0])
lgrtm
In reality the regex gives the result that you need but not doing as you suggest, that is, instead of identifying the vowels and removing them, it returns only the consonants.
DEMO
Edited Version without regex:
I’m not in time and on a very limited machine, so I developed a python version without the use of regex, I think it would be easy to convert to C, if you want to try the repl I try to help.
vogais = ['a', 'e', 'i', 'o', 'u']
string = 'Algoritmo'
result = ''
# Percorre todas as letras da string
for x in string:
# convert p/ minúscula e verifica se esta em vogais
if x.lower() not in vogais:
# se NÃO estiver em vogais, adiciona na string resultante
result += x
# Imprime o resultado
print (result)
lgrtm
See the execution in repl.it.
Use of regex is mandatory?
– Francisco
It is not, but I thought it would be better to use, would have another way to do this ? For example, using an if that checks each vowel, and then cut this part of the word ?
– Monteiro
I tried to do some things but I did not get any considerable result. See here.
– Francisco
And if you change that regex[i] = '.' to something else, it wouldn’t work ?
– Monteiro
Yes, you can change the
'.'
by any other character.– Francisco
I need to somehow make the final output normal, not with extra spaces or characters.
– Monteiro