I refer to the question how to extract a substring from inside a string in Python? and have further question.
What if my string is something like:
gfgfdAAA1234ZZZsddgAAA4567ZZZuijjk
I want to extract 1234
and 4567
, is it stored as a list?
I refer to the question how to extract a substring from inside a string in Python? and have further question.
What if my string is something like:
gfgfdAAA1234ZZZsddgAAA4567ZZZuijjk
I want to extract 1234
and 4567
, is it stored as a list?
import re
re.findall('\d+','gfgfdAAA1234ZZZsddgAAA4567ZZZuijjk')
['1234', '4567']
Let me know if I'm not understanding you correctly, but you can certainly extract these substrings as a list
, though you do it slightly differently:
>>> import re
>>> text = 'gfgfdAAA1234ZZZsddgAAA4567ZZZuijjk'
>>> re.findall(r'[0-9]{4}', text)
['1234', '4567']