Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 打印两个变量子字符串之间的字符串_Python_Regex - Fatal编程技术网

Python 打印两个变量子字符串之间的字符串

Python 打印两个变量子字符串之间的字符串,python,regex,Python,Regex,我正在寻找以下信息: dna = '**atg**abcdefghijk**tga**aa' start = 'atg' stop = 'tag' or 'taa' or 'tga' ['abcdefghijk'] 我想得到开始和停止之间的所有字符。我试过: print (dna.find(start:stop)) 但我一直在说“:”是无效语法。您可以使用正则表达式来帮助查找任何合适的匹配项,如下所示: import re dna = 'atgabcdefghijktgaaa' st

我正在寻找以下信息:

dna = '**atg**abcdefghijk**tga**aa'

start = 'atg'

stop = 'tag' or 'taa' or 'tga'
['abcdefghijk']
我想得到开始和停止之间的所有字符。我试过:

print (dna.find(start:stop))

但我一直在说“:”是无效语法。

您可以使用正则表达式来帮助查找任何合适的匹配项,如下所示:

import re

dna = 'atgabcdefghijktgaaa'
start = 'atg'
stop = ['tag', 'taa', 'tga']

print re.findall(r'{}(.*?)(?:{})'.format(start, '|'.join(stop)), dna)
这将显示以下内容:

dna = '**atg**abcdefghijk**tga**aa'

start = 'atg'

stop = 'tag' or 'taa' or 'tga'
['abcdefghijk']

嗯,是的。这不是你所说的“发现”。而且,我不认为find做了你认为它做的事情。我怀疑你想要切片。可能是重复的