快捷搜索:  汽车  科技

python 正则表达式提取某列日期(re正则表达示提取字符串中的数字)

python 正则表达式提取某列日期(re正则表达示提取字符串中的数字)

python 正则表达式提取某列日期(re正则表达示提取字符串中的数字)(1)

# -*- coding:utf-8 -*- import re def get_num_re(str_wm): ##提取正负数字和百分数 wm_nv = re.findall(r'([-]?\d .\d [%]|[-]?\d .\d )' str_wm) return wm_nv def get_time_re(str_wm): #取时间 "2020-02-10 20:49:21.731640" wm_nv = re.findall(r'(\d [-]\d [-]\d \s\d [:]\d [:]\d [.]\d )' str(str_wm)) return wm_nv if __name__ == '__main__': str_wm = ' 测试30摄氏度,-125米深,时间:2020-02-10 20:49:21.731640' s1 = get_num_re(str_wm) s2 = get_time_re(str_wm) print(s1) print(s2) """ 运行结果: ['-125' '2020-02' '-10 20' '49:21' '731640'] ['2020-02-10 20:49:21.731640'] Process finished with exit code 0 """ """ Pgabc 2022000014 author : Pgabc www.wmdbsoft.com """

猜您喜欢: