Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find words that matches the 3 consecutive vowels Regex

text = "Life is beautiful"
pattern = r"[aeiou]{3,}"
result = re.findall(pattern, text)
print(result)

desired result: ['beautiful']

the output I get: ['eau']

I have tried googling and etc....I found multiple answers but none of them worked!! I am new to regex so maybe I am having issues but I am not sure how to get this to out

I have tried using r"\b[abcde]{3,}\b" still nothing SO please help!!

like image 767
Prab Avatar asked Sep 11 '25 15:09

Prab


1 Answers

Your regex only captures the 3 consecutive vowels, so you need to expand it to capture the rest of the word. This can be done by looking for a sequence of letters between two word breaks and using a positive lookahead for 3 consecutive vowels within the sequence. For example:

import re

text = "Life is beautiful"
pattern = r"\b(?=[a-z]*[aeiou]{3})[a-z]+\b"
result = re.findall(pattern, text, re.I)
print(result)

Output:

['beautiful']
like image 89
Nick Avatar answered Sep 13 '25 07:09

Nick