[英]How to find more than one substring from a string in Python
For example if i have a string 'ATGAGGGATAGAGGGTTGGGAGAGATGGATAGGGGATAGATTG' i have to get substring between ATG and TTG , as we can see there are two of these kinds in a string. 例如,如果我有一个字符串'ATGAGGGATAGAGGGTTGGGAGAGATGGATAGGGGATAGATTG',我必须得到ATG和TTG之间的子串,因为我们可以看到字符串中有两种。
I am not able to figure out anyway to do it , plz help me thru it! 无论如何我都无法弄明白,plz通过它帮助我!
Using regular expression can easily get you there. 使用正则表达式可以轻松实现目标。
For example: 例如:
import re
a = 'ATGAGGGATAGAGGGTTGGGAGAGATGGATAGGGGATAGATTG'
print re.findall("ATG(.*?)TTG", a)
Output: 输出:
['AGGGATAGAGGG', 'GATAGGGGATAGA']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.