Let\'s say I have a number with a recurring pattern, i.e. there exists a string of digits that repeat themselves in order to make the number in question. For example, such a
(.+?)\1+
Try this. Grab the capture. See demo.
import re p = re.compile(ur'(.+?)\1+') test_str = u"1234123412341234" re.findall(p, test_str)
Add anchors and flag Multiline if you want the regex to fail on 12341234123123, which should return None.
Multiline
12341234123123
None
^(.+?)\1+$
See demo.