Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Regex solution in Clear category for Long Repeat by todd.larson5
import re
def long_repeat(line):
"""
Regex patern explained ((\w)\2*)
1. (/w) any letter (.) could be used for any character
2. \2* is a backreference to the second capture group (\w)
3. Without outer most brackets only a single character would be captured
by findall
"""
regexResults = re.findall(r'((\w)\2*)', line)
# If the string is blank
if regexResults == []:
return 0
# Use the legth of the first capture group to find longest match
return len(max(regexResults, key=lambda x: len(x[0]))[0])
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert long_repeat('sdsffffse') == 4, "First"
assert long_repeat('ddvvrwwwrggg') == 3, "Second"
print('"Run" is good. How is "Check"?')
Oct. 9, 2017