[英]python regular expression search not finding underscore in path
我有一個遵循某種結構的長文件,我想解析這個文件以提取一個名為sample
的 object:
名為paths_text.txt
的文件是這樣的:
/groups/cgsd/javed/validation_set/LeungSY_Targeted_SS-190528-01a/Clean/pfg001G_1_Clean.fastq.gz
/groups/cgsd/javed/validation_set/LeungSY_Targeted_SS-190528-01a/Clean/pfg001G_2_Clean.fastq.gz
/groups/cgsd/javed/validation_set/LeungSY_Targeted_SS-190528-01a/Clean/pfg001T_1_Clean.fastq.gz
/groups/cgsd/javed/validation_set/LeungSY_Targeted_SS-190528-01a/Clean/pfg001T_2_Clean.fastq.gz
我的代碼運行良好,如下所示:
import os
os.chdir('/groups/cgsd/alexandre/python_code')
import re
with open('./src/paths_text.txt') as f:
for line in f:
sample = re.search(r'pfg\d+',line)
print(sample)
但是當我搜索下划線時,我的匹配結果是None
,為什么?
import os
os.chdir('/groups/cgsd/alexandre/python_code')
import re
with open('./src/paths_text.txt') as f:
for line in f:
sample = re.search(r'pfg\d+_',line)
print(sample)
因為pfg001
和_
之間有G
和T
。 \d+
只計算數字。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.