function hexToString(hex) { let str = ''; for (let i = 0; i < hex.length; i += 2) { str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); } return str; } const hexData = "32 30 32 34 2F 38 2F 31 35 2F 31 31 3A 33 33 3A 33 33 3B CA D5 CB F5 D1 B9 3A 31 32 34 20 6D 6D 48 67 3B CA E6 D5 C5 D1 B9 3A 38 30 20 6D 6D 48 67 3B C2 F6 B2 AB 3A 38 32 20 B4 CE 2F B7 D6 D6 D3 3B 0D 0A"; const originalString = hexToString(hexData.replace(/\s/g, '')); // 移除空格 console.log(originalString); console.log('----------------') // 解析后的原始字符串 const data = originalString; // 使用正则表达式匹配收缩压、舒张压和脉搏的值 const systolicPressureMatch = data.match(/收缩压:(\d+) mmHg/); const diastolicPressureMatch = data.match(/舒张压:(\d+) mmHg/); const pulseMatch = data.match(/脉搏:(\d+) 次\/分钟/); // 提取匹配的值 const systolicPressure = systolicPressureMatch ? parseInt(systolicPressureMatch[1], 10) : null; const diastolicPressure = diastolicPressureMatch ? parseInt(diastolicPressureMatch[1], 10) : null; const pulse = pulseMatch ? parseInt(pulseMatch[1], 10) : null; // 输出结果 console.log("收缩压:", systolicPressure); // 124 console.log("舒张压:", diastolicPressure); // 80 console.log("脉搏:", pulse); // 82