jeudi 27 mai 2021

python substring based on a specific pattern

I am very new to Python. I am trying to substring a specific pattern from a long string of txt. This specific pattern occur multiple times in the same txt. For example, s = 'apple/gfgfdAAA1234ZZZuijjk/pear apple/009456/pear apple/dsakjdaghdj/pear' start = s.find('apple') end = s.find('pear', start) s[start:end] This was my initial attempt. However, it only gives me the very first chunk of text, which is 'gfgfdAAA1234ZZZuijjk'; instead, I will also need '009456' and 'dsakjdaghdj'.

Aucun commentaire:

Enregistrer un commentaire