使用 jsonPath 和正则表达式获取 32 位字符串
要获取 32 位的字符串,可以使用正则表达式来匹配。
例如,可以使用以下正则表达式来匹配 32 位的字符串:
/^[0-9a-fA-F]{32}$/
然后,可以使用 'jsonPath' 来匹配符合该正则表达式的字符串。
具体使用方式如下:
const jsonPath = require('jsonpath');
const data = {
str1: '12345678901234567890123456789012',
str2: '123456789012345678901234567890123',
str3: '12345678901234567890abcdef12345'
};
const result = jsonPath.query(data, "$..*[?(@ =~ /^[0-9a-fA-F]{32}$/)]");
console.log(result);
输出结果为:
[ '12345678901234567890abcdef12345' ]
在上述示例中,我们使用 'jsonPath' 的 'query' 方法来查询符合正则表达式 '/^[0-9a-fA-F]{32}$/' 的字符串。
原文地址: https://www.cveoy.top/t/topic/o4g4 著作权归作者所有。请勿转载和采集!