Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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
Regex Python-如何获取不连续的事件数?_Python_Regex - Fatal编程技术网

Regex Python-如何获取不连续的事件数?

Regex Python-如何获取不连续的事件数?,python,regex,Python,Regex,这是我的代码,我想获得基于此模式的组合数:x-y-x,示例:“UBU”、“ANA”、“INI” 重新导入 图案=r“(?P[a-z])(?P=名称)” 打印(len(re.findall(pattern,“hello”))#应返回0:OK print(len(re.findall(pattern,“mirror”))#应返回1,因为存在“ror”:OK print(len(re.findall(pattern,“irir”))#应该返回2,因为有“iri”和“rir”:只返回1 当一部分组合被

这是我的代码,我想获得基于此模式的组合数:
x-y-x
,示例:
“UBU”、“ANA”、“INI”

重新导入
图案=r“(?P[a-z])(?P=名称)”
打印(len(re.findall(pattern,“hello”))#应返回0:OK
print(len(re.findall(pattern,“mirror”))#应返回1,因为存在“ror”:OK
print(len(re.findall(pattern,“irir”))#应该返回2,因为有“iri”和“rir”:只返回1
当一部分组合被叠加到另一个组合(如“iri”中“rir”的前两个字母)中时,它不起作用

您知道如何获得这些组合的正确数量吗(对于第三个示例)?
提前非常感谢

叠瓦是植物学特有的术语。如果你想找到一些有用的信息,你必须寻找术语重叠。谢谢,我不是英国人,所以我在搜索要使用的术语:)术语重叠是植物学特有的。如果你想找到一些有用的信息,你必须寻找术语重叠。谢谢,我不是英国人,所以我正在搜索要使用的术语:)
def pattern_counter(word):
    return sum([1 for index, letter in enumerate(word[:(len(word)-2)]) if letter == word[index+2]])

word1 = "hello"
word2 = "mirror"
word3 = "irir"

print(pattern_counter(word1)) # prints 0
print(pattern_counter(word2)) # prints 1
print(pattern_counter(word3)) # prints 2
def pattern_counter(word):
    return sum([1 for index, letter in enumerate(word[:(len(word)-2)]) if letter == word[index+2]])

word1 = "hello"
word2 = "mirror"
word3 = "irir"

print(pattern_counter(word1)) # prints 0
print(pattern_counter(word2)) # prints 1
print(pattern_counter(word3)) # prints 2