Advertisement
here2share

# str_longest_repeat.py

Jul 18th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. # str_longest_repeat.py - excl. non-letters
  2. import re
  3.  
  4. text = 'hello12345helloworld!12345abchelloworld!xyz12345abchelloworld!'
  5. largest = ''
  6. i = 1
  7.  
  8. while 1:
  9.     m = re.search("(" + ("\w" * i) + ").*\\1.*\\1", text)
  10.     if not m:
  11.         break
  12.     largest = m.group(1)
  13.     i += 1
  14.  
  15. print largest    # helloworld
  16. print text.count(largest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement