Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 正则表达式模式来查找最长的元音序列_Python_Regex_Pattern Matching - Fatal编程技术网

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很好,请考虑下面的答案。