[英]how to extract a multiple substring from inside a string in Python?
I refer to the question how to extract a substring from inside a string in Python? 我指的是如何从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? 我想提取
1234
和4567
,是否将其存储为列表?
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: 如果我对您的理解不正确,请告诉我,但是您可以将这些子字符串提取为
list
,尽管您做的略有不同:
>>> import re
>>> text = 'gfgfdAAA1234ZZZsddgAAA4567ZZZuijjk'
>>> re.findall(r'[0-9]{4}', text)
['1234', '4567']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.