Take for example the following strings
0.714285714285714285714285714285714285714285
0.111111111111111111111111111111111111111111
0.166666666666666666666666666666666666666666
I want to find the sub string that is repeating repetition for each.
714285
1
6
How can I do this in python. Using regex is okay, I tried the following:
import re
testString = "0.714285714285714285714285714285714285714285"
print(re.search(r"(.+)\1", testString).group(1))
This gives me the (wrong) output:
714285714285714285
It should be 7814285
How do I fix this? Is there way to improve my regex or is regex the wrong tool for this job? Maybe python has an awesome built in for this? Is there anyway to do use this with or without regex?
EDIT Before posting an answer check with the test case
0.0022271714922048997772828507795100222717149220489977728285077951002227171492204899777282850779510022
It should return 00222717149220489977728285077951