如何从JSON数据中提取特定格式的版本号
要获取result中的第一个key值的第二个正则表达式,可以使用以下代码:
import re
response = {
"code": "0",
"result": {
"8a7400e98905f75d01890657e19b0a2b": 'dops/U2.19.2'
},
"status": 200,
"timestamp": 1688028570331
}
key = list(response['result'].keys())[0]
match = re.search(r'\d+\.\d+\.\d+', response['result'][key])
if match:
version = match.group(0)
print(version)
输出结果为:U2.19.2
这里使用了re模块的search函数来查找第一个匹配的版本号(由一串数字、点号和数字组成)。如果匹配成功,则打印版本号。
原文地址: https://www.cveoy.top/t/topic/o34y 著作权归作者所有。请勿转载和采集!