Reputation: 504
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!!
Upvotes: 4
Views: 2971
Reputation: 11
The first part of the regex looks for all letters, upper or lower case (as well as numbers and underscores which is not necessary), but for the purpose of this question it works. We just need to find characters leading up to a word with (at least) three vowels in a row. Then we finish it off by looking for lowercase letters at the tail end of the word if any remain.
pattern = r"[\w]+[aeiou]{3,}[a-z]+"
Upvotes: 1
Reputation: 1
I know it's a late reply but just wanted to share this for whoever searches this up!
Answer: pattern = r"\b[a-zA-Z][aeiou]{3,}[a-z]\b" OR experimenting with [\w]* instead of [a-zA-Z]
change the first match from [a-z] to [a-zA-Z]
Upvotes: 0
Reputation: 1
pattern=r"\b\w*[aeiou]{3,}\w*\b"
\w* For any alpha Alphanumerics that "could" exist before and after the vowels
Upvotes: 0
Reputation: 1
A little improvement on the former solution would be using \w instead a-z as the character classes (This will match lower and uppercase letters)
\b[\w]+[aeiou]{3,}[\w]+\b
Cheers!
Upvotes: 0
Reputation: 147266
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']
Upvotes: 4