0 points

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


dashboard

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

Posted by @PehShin #python

>>> matches = re.findall(f'(?:{p})+', s)
>>> matches
['HELLO', 'HELLO', 'HELLOHELLOHELLO', 'HELLOHELLO']

>> max(map(len, matches)) // len(p)
3
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

https://stackoverflow.com/questions/59746080/count-max-consecutive-re-groups-in-a-string