I'm trying to make a regular expression that matches a String with 3 or more vowels.
I've tried this one:
[aeiou]{3,}
But it only works when the vowels are in a sequence. Any tips ?
For example:
There are several ways to do it and in this case keeping it simple will probably be the most helpful to future devs maintaining that code. That's a fun part about regexes, you can make them very efficient and clever and then very hard for somebody who doesn't do them often to update.
import re
regex = "[aeiou].*[aeiou].*[aeiou]"
mylist = [
"Samuel", #yes!
"JOAN", #no!
"Sol Manuel", #yes!
"", #no!
]
for text in mylist:
if re.search(regex, text, re.IGNORECASE):
print ("Winner!")
else:
print ("Nein!")
You could also adjust each part to be [aeiouAEIOU] if you don't have an ignore case flag in your language of choice. Good luck! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With