Python: Regex not capturing backslash

Viewed 19

I have the following question: I have the following string:

message_cell = '{1:abc1}{2:abc2}{3:{108:abc3}{111:abc4}{121:abc5}}{4:\n:20:abc6\n:23B:abc7\n:32A:abc8\n:33B:abc9\n:50F:/abc10\n:59:/abc-}'

I want to extract the text between ":" and "\"symbols. Up to now, I have tried

column_names1 = re.findall(r':(.*?)\' , message_cell)
column_names2 = re.findall(r':(.*?)\\' , message_cell)
column_names3 = re.findall(r':(.*?)\\\' , message_cell)
column_names4 = re.findall(r':(.*?)\\\' , message_cell)

The outputs are either SyntaxError: EOL while scanning string literal for odd number of backslashes or [] for even number of backslashes. I was wondering what the proper why of extracting the text is.

Thanks a lot in advance.

0 Answers
Related