我需要一个Regex,它匹配每个比特流,其中没有5跟随位发生。例如:
010001111 -> matches
010011111 -> does not match我能够创建一个长度可以除以5的Regex。
((0|1){4}(?!\2)(0|1))+有没有一种不需要5倍的长度的方法?
发布于 2016-02-04 19:43:59
发布于 2016-02-04 19:52:48
您可以匹配该位,并计数其出现情况:
>>> len(re.findall('(?=(1))', '010001111'))
5
>>> len(re.findall('(?=(1))', '010011111'))
6
>>> len(re.findall('(?=(1))', '010110111'))
6https://stackoverflow.com/questions/35209261
复制相似问题