0 points

python - Count max consecutive recurring groups in a string - Stack Overflow


Thu Jul 09 2020 13:14:43 GMT+0000 (UTC)

Posted by @PehShin #python

>>> matches = re.findall(f'(?:{p})+', s)
>>> matches

>> max(map(len, matches)) // len(p)
content_copy Copy

Trying to apply findall on just a pattern will simply return a list of all instances where the pattern shows up, but does not join up instances of consecutive patterns. re.findall(f'(?:{p})+', s) performs this role, before max(map(len, matches)) // len(p) gives the highest number of consecutive repetitions