+ 8

Find all characters, that are not in brackets

"hallo##abc[def]fg[hij]##[def]bc" I want to find hallo, abc,fg and bc but only find fg. import re field = "hallo##abc[def]fg[hij]##[def]bc" x = re.findall("[(?<=\])^][a-z\#]*[(?=\[)(?=$)]", field)

22nd Jul 2020, 9:50 AM
Oma Falk
Oma Falk - avatar
9 Respostas
23rd Jul 2020, 9:19 AM
Lothar
Lothar - avatar
+ 6
For all those who are not familiar with RegEx, (e.g. me 😅) here another solution: inp = "hallo##abc[def]fg[hij]##[def]bc" inp = inp.replace('##',',') inp = list(inp) while '[' in inp: inp[inp.index('['):inp.index(']')+1] = '' print(''.join([i for i in inp])) It can be modified to create a single string, not words.
22nd Jul 2020, 3:49 PM
Lothar
Lothar - avatar
+ 4
Lothar I'm also not familiar that even I didn't knew that the 're' module is called regex😅 before this thread.
22nd Jul 2020, 3:59 PM
Arctic Fox
Arctic Fox - avatar
+ 1
x = re.findall("(.*?)(?:\[.*?\]|$)",field)
22nd Jul 2020, 10:13 AM
Bahha┣
Bahha┣ - avatar