37,722
社区成员
发帖
与我相关
我的任务
分享
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import re
flist = ['123.txt', 'hlof124.c', 'yes123.txt', '123', 'no123',
'just_is_1_2.cpp']
date = input('input the date: ')
pattern = re.compile(date)
for x in flist:
match = pattern.search(x)
if match:
print(x)
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import re
flist = ['123.txt', 'hlof124.c', 'yes123.txt', '123', 'no123',
'just_is_1_2.cpp']
date = input('input the date: ')
pattern = re.compile(r'.*' + date + '.*')
for x in flist:
match = pattern.search(x)
#print(x, match)
if match:
print(x)
pattern=re.compile(r'(?<!\d)20120701(?!\d)')
pattern=re.compile(r'20120701')
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
http://topic.csdn.net/u/20120724/16/ffe1f14c-4e61-40c3-aa98-473c92c0421f.html?5433
"""
import os;
import re;
#inputList = [ "mm11280020120701.txt", "mg20120701.txt","system112720120701"];
fileList = "mm11280020120701.txt,mg20120701.txt,system112720120701"
#如果你确保整个文件名中,只有你的日期带数字,那么可以写为:
#dataPattern = r"[^\d]*\d+[^\d]*";
dataPattern = r"\d+";
pattern = re.compile(dataPattern); # --匹配规则 --这个地方如何写
matchedList = pattern.findall(fileList);
if matchedList:
print "matchedList=",matchedList;#matchedList= ['11280020120701', '20120701', '112720120701']