Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.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 - Fatal编程技术网

Python正则表达式搜索与匹配

Python正则表达式搜索与匹配,python,regex,Python,Regex,我正在尝试使用python正则表达式来匹配“BrahuiHan”或“BrahuiYourba” >> re.search(r'((Brahui|Han|Yoruba)+\d+)', '10xBrahuiHan50_10xBrahuiYoruba50n4').groups() ('BrahuiHan50', 'Han') 这只返回一组,第一组,我想它也应该返回第二组。i、 e BrahuiYoruba如果要捕获模式的所有引用,需要使用: re.search只会捕获第一次出现的内容。

我正在尝试使用python正则表达式来匹配“BrahuiHan”或“BrahuiYourba”

>> re.search(r'((Brahui|Han|Yoruba)+\d+)', '10xBrahuiHan50_10xBrahuiYoruba50n4').groups()

('BrahuiHan50', 'Han')

这只返回一组,第一组,我想它也应该返回第二组。i、 e BrahuiYoruba

如果要捕获模式的所有引用,需要使用:

re.search
只会捕获第一次出现的内容。

试试看

import re
regex = re.compile("((Brahui|Han|Yoruba)\\d{1,})")
testString = "" # fill this in
matchArray = regex.findall(testString)
# the matchArray variable contains the list of matches
下面是演示

图示:

import re
regex = re.compile("((Brahui|Han|Yoruba)\\d{1,})")
testString = "" # fill this in
matchArray = regex.findall(testString)
# the matchArray variable contains the list of matches