您好,我对python正则表达式感到困惑,下面是我的代码:
import os,re,sys
t="LOC_Os01g01010.1 GO:0030234 F enzyme regulator activity IEA TAIR:AT3G59570"
k =['LOC_Os01g01010']
re_search=re.search(re.escape(k[0] + r'.1 GO:\d{7}'),t,re.M|re.I|re.S)
if re_search is None:
pass
else:
print re_search.group()
“t”是我的数据,“k”是我的目标。你知道吗
我想要的是“LOC\u Os01g01010.1 GO:0030234”或“GO:0030234”,但我不知道如何编写模式。你知道吗
如果有任何解决方案,有(可证明)无限的解决方案,一个正则表达式,可以匹配一个无界字符串中的一组有限的例子。你知道吗
这是一种包容的方式,你需要更具体,因为给我们只有一个例子,你试图匹配,我们将能够为你提供多种解决方案,取决于进一步(未指明)的假设,我们添加自己。你知道吗
以下是一些假设:
我相信以下几点可以解决你的问题:
考虑到你的例子和在
LOC_********.*
中星星可以是集合[a-zA-Z0-9]中的任何东西的期望,我建议:python regexthing.py
当我用python2.7运行它时,会产生LOC_Os01g01010
。(LOC_[0-9A-Za-z]*)
是一个捕获组,它捕获与表达式LOC_[0-9A-Z]*
匹配的任何内容。此表达式将匹配LOC_
、LOC_ABCabc123
、LOC_a1B2C
等我希望这能回答你的问题。你知道吗
相关问题 更多 >
编程相关推荐