2
import re
    def multi_vowel_words(text):
        pattern =r"\b\w[aeiou]{3,},?\s?.*\w[aeiou]{3,}.*\b"
        result = re.findall(pattern, text)
        return result

我在哪里做错了

运行我的代码后,我得到了这个:

[]
['queen is courageous and gracious']
['quietly and await their delicious dinner']
[]
[]

#below this are desired outputs
print(multi_vowel_words("Life is beautiful")) 
# ['beautiful']

print(multi_vowel_words("Obviously, the queen is courageous and 
gracious.")) 

# ['Obviously', 'queen', 'courageous', 'gracious']

print(multi_vowel_words("The rambunctious children had to sit quietly and 
await their delicious 
dinner.")) 
# ['rambunctious', 'quietly', 'delicious']

print(multi_vowel_words("The order of a data queue is First In First Out 
(FIFO)")) 
   # ['queue']

print(multi_vowel_words("Hello world!")) 
   # []
print(multi_vowel_words("The order of a data queue is First In First Out 

(FIFO)")) # ['queue']

print(multi_vowel_words("Hello world!")) # []
4

4 回答 4

5

试图尝试回答这个问题。一个简单的模式来检查三个连续的元音怎么样

def multi_vowel_words(text):
    pattern =r"\b\w*[aeiou]{3,}\w*\b"
    result = re.findall(pattern, text)
    return result
于 2020-04-15T19:46:43.863 回答
3

每个人都在使用\w匹配元音的前后字符。这是错误的,因为\w匹配任何单个字母、数字或下划线(与 相同[a-zA-Z0-9_])。正确的模式应该是:

pattern = r"\b[A-Za-z]*[aeiou]{3,}[A-Za-z]*\b"
于 2020-09-23T18:46:23.127 回答
1
pattern = r"\w*[aeiou]{3,}\w*"

这将起作用。

于 2020-09-15T16:36:45.030 回答
0

假设我猜对了你的意图,这就是你需要的正则表达式:

r"\b\w*[aeiou]{3,}\w*\b"
于 2020-04-15T19:53:14.297 回答