Python 正则表达式模式来查找最长的元音序列
我下面的代码用于定位元音的第一个匹配项,在本例中是Python 正则表达式模式来查找最长的元音序列,python,regex,pattern-matching,Python,Regex,Pattern Matching,我下面的代码用于定位元音的第一个匹配项,在本例中是'ua',但是如何配置正则表达式1)在第一次查找之前搜索整个字符串,2)一旦完成步骤1,确定所有模式中哪一个显示元音的最长并发性 import re s = "quality" matches = re.search(r"[aeiou]+", s) matchlist = matches.group().split(', ') print(len(matchlist)) 抓取所有匹配项,然后查找最长的匹配项: import re s = "qu
'ua'
,但是如何配置正则表达式1)在第一次查找之前搜索整个字符串,2)一旦完成步骤1,确定所有模式中哪一个显示元音的最长并发性
import re
s = "quality"
matches = re.search(r"[aeiou]+", s)
matchlist = matches.group().split(', ')
print(len(matchlist))
抓取所有匹配项,然后查找最长的匹配项:
import re
s = "quality"
matches = re.findall(r"[aeiou]+", s) # Finds all chunks of vowel letters
print(max(matches, key=len)) # Gets the longest item in the list
# => ua
请参阅。抓取所有匹配项,然后找到最长的匹配项,请参阅。您为什么讨厌
y
?有时也是元音<代码>((?:[aeiou]| y(?![aeiou])+)Jibz先生,有什么反馈吗?@WiktorStribiż您的解决方案是否正确on@Mr.Jibz很好,请考虑下面的答案。