python正則日期
發布時間: 2023-08-12 05:27:31
㈠ python 正則 怎樣找出文件中的日期 如19 november 2011 並且替換為標准格式 2011-11-19
沒看懂你什麼意思~~
不過正則替換是用re模塊的re.sub()
標准時間讀取輸出是用time模塊的strptime()和strftime()
根據你的需要應該能搞定~
㈡ python replace正則怎麼用
# encoding: UTF-8
import re
s="今天是2015年10月1日國慶節,明天是2015年10月2日";
result = s.replace("2015年10月1日", "00") #只能用於字元串替換
print result;
result, number = re.subn("\d+年\d+月\d+日", "00", s) #可以用於正則的替換
print result;
print number;
㈢ Python怎麼從年月日字元串中取出年份月份
切片或正則匹配。
切片:
year = 'YD210901-03'[2:4]
month = 'YD210901-03'[4:6]
正則匹配:
year, month = re.findall(r'YD(dd)(dd)dd-dd', 'YD210901-03')[0]
熱點內容