我必须只提取那些在notepad++中包含下划线的字符串。我的文件是这样的
T-cell_stimulation
transcription_factor
NF-kappa_B
kappa_B_site
HIV-1_long_terminal_repeat
HIV-1
HIV-2_enhancer
HIV-2
monocyte
T_cell
cis-acting_element
kappa_B_site
purine-rich_binding_site我想要的输出是
T-cell_stimulation
transcription_factor
NF-kappa_B
kappa_B_site
HIV-1_long_terminal_repeat
HIV-2_enhancer
T_cell
cis-acting_element
kappa_B_site
purine-rich_binding_site发布于 2015-04-11 11:12:09
查看Notepad++的regex搜索。
类似于以下内容:
.*_.*发布于 2015-04-11 11:32:09
我通过python代码解决了我的问题
import re;
file = "C:/Python26/test.txt";
f=open("rzlt.txt",'w')
pattern ='\w+_\w+[_\w+]*|\w+-\w+[-\w+]*';
with open(file,'r') as rf:
lines = rf.readlines();
c=0;
for word in lines:
if re.match(pattern, word):
f.write( word)
c=c+1;
print c;
f.close(); https://stackoverflow.com/questions/29573490
复制相似问题