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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With