python – 使用正则表达式从字符串中提取数字
发布时间:2020-12-20 12:29:35 所属栏目:Python 来源:网络整理
导读:我有以下字符串: fname="VDSKBLAG00120C02 (10).gif" 如何从字符串fname中提取值10(使用re)? 解决方法 regex = re.compile(r"(?=()d+(?=))")value = int(re.search(regex,fname).group(0)) 说明: (?=() # Assert that the previous character is a (
我有以下字符串:
fname="VDSKBLAG00120C02 (10).gif" 如何从字符串fname中提取值10(使用re)? 解决方法regex = re.compile(r"(?<=()d+(?=))") value = int(re.search(regex,fname).group(0)) 说明: (?<=() # Assert that the previous character is a ( d+ # Match one or more digits (?=)) # Assert that the next character is a ) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |