Python line break depending on character pattern

I have a line 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 break this down into a list with values:

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

I tried regular expressions as follows:

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

tries to combine parts starting with a digit, and then three colons, then any character until it is reached anywhere [0-9]: or the end of a line. This seems completely wrong, but I don't understand how to proceed here.

thanks Marcus

+4
source share
2 answers

Use expression to view

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

(\d:::\{.*?\}(?=\d))|(\d:::\{.*?\})$

http://regexr.com?34opb

+2
source

Source: https://habr.com/ru/post/1479052/


All Articles