breaking a string in python depending on character pattern

breaking a string in python depending on character pattern

I have a string something like this:

a = '5:::{"test":[{"a":1,"b":2},{"a":2,"b":3}]}4:::{"something":[{"d":1,"e":2},{"d":2,"e":3}]}'

I would like to split this into a list with the values being:

['5:::{"test":[{"a":1,"b":2},{"a":2,"b":3}]}','4:::{"something":[{"d":1,"e":2},{"d":2,"e":3}]}']

I tried regular expressions like this:

b = re.findall(r'[0-9]:::.*(?=[0-9]:::)|(?=$)',a)

trying to match parts starting with a digit, followed by three colons, then any character until either a [0-9]::: is hit or the end of the string. This seems completely wrong but I’m at a loss on how to continue here.

Thx
Markus

Use a lookahead assertion

re.findall(r'd:::.+?(?=d:::|$)', a)
.
.
.
.