python how to extract a string from another string

Solutions on MaxInterview for python how to extract a string from another string by the best coders in the world

showing results for - "python how to extract a string from another string"
Valentina
12 Jan 2021
1>>> s = 'gfgfdAAA1234ZZZuijjk'
2>>> start = s.find('AAA') + 3
3>>> end = s.find('ZZZ', start)
4>>> s[start:end]
5'1234'
6
Lola
26 Jan 2018
1import re
2
3text = 'gfgfdAAA1234ZZZuijjk'
4
5m = re.search('AAA(.+?)ZZZ', text)
6if m:
7    found = m.group(1)
8
9# found: 1234
10