正则综合处理处理字符串.py
import re list = ["http://11.192.223.153/peaxiimg/104_FKIZT50QN72Q.XRAY_02_2019...jpg", "http://11.192.223.153/peaxiimg/104.pokkkQN72Qpp.XRAY_02_2019...jpg", "http://11.192.223.153/peaxiimg/104_ujjjjj50QN7Q.XRAY_02_2019...jpg", "http://11.192.223.153/peaxiimg/N104_N72k.ujjjjj50QN2Q.XRAY_02_2019...jpg" ] with open("test.txt", "r") as f: linelist = [] hahalist = [] for line in f.readlines(): line = line.strip('\n') # 去掉列表中每一个元素的换行符 linelist.append(line) print(line) print(linelist) for i in list: a = re.findall(r"(.+)/", i) b = re.sub(a[0], '', i) c = b.split('.') haha = '' if '_' in c[0]: if len(c[0].split('_')[1]) == 12: haha = c[0].split('_')[1] if len(c[1]) == 12 and '_' not in c[1]: haha = c[1] if haha in linelist: hahalist.append(i) print(hahalist)
用户评论