+ 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)
5 Respuestas
+ 7
♤♢☞ 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 ☜♢♤ , What do you mean exactly when you say that this is a dangerous solution?
+ 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.
+ 4
Lothar
I'm also not familiar that even I didn't knew that the 're' module is called regex😅
before this thread.
+ 1
x = re.findall("(.*?)(?:\[.*?\]|$)",field)
0
♤♢☞ 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 ☜♢♤ Bahha🐧
uffff please explain