You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.0 KiB
58 lines
2.0 KiB
import re, json
|
|
|
|
# 模拟后端实际返回的 error_report(根据用户截图重建)
|
|
raw = (
|
|
"### 超声报告质控分析报告\n\n"
|
|
"#### 🎯 综合评分:**60 分**\n\n"
|
|
"#### 📝 详细建议清单:\n"
|
|
"- **[严重错误]** 左膝关节髌骨、骨外侧错位;\n\n"
|
|
"```json\n"
|
|
'{\n "score": 60,\n "issues": [\n'
|
|
' {\n "original": "左膝关节髌骨、骨外侧错位;",\n'
|
|
' "reason": "侧位冲突",\n "suggestion": "修正为右膝",\n'
|
|
' "type": "严重错误"\n }\n ],\n'
|
|
' "corrected_fields": {"bSee": "右膝...", "bHint": "右膝..."}\n}\n'
|
|
"```\n"
|
|
)
|
|
|
|
print("=== 原始字符串末尾 ===")
|
|
print(repr(raw[-100:]))
|
|
|
|
# 测试反引号字符编码
|
|
idx = raw.find("```json")
|
|
print(f"\n=== 反引号位置: {idx} ===")
|
|
if idx >= 0:
|
|
print(f"字符编码: {[ord(c) for c in raw[idx:idx+7]]}")
|
|
print(f"内容: {repr(raw[idx:idx+20])}")
|
|
|
|
# 测试正则匹配
|
|
pattern = r"```json[\s\S]*?```"
|
|
blocks = re.findall(pattern, raw)
|
|
print(f"\n=== Python正则找到 {len(blocks)} 个代码块 ===")
|
|
for i, b in enumerate(blocks):
|
|
print(f"Block {i}: {repr(b[:80])}")
|
|
|
|
# 模拟JS的matchAll
|
|
import re
|
|
all_blocks = list(re.finditer(r"```json([\s\S]*?)```", raw))
|
|
print(f"\n=== finditer找到 {len(all_blocks)} 个 ===")
|
|
for m in all_blocks:
|
|
try:
|
|
parsed = json.loads(m.group(1).strip())
|
|
print(f"解析成功: score={parsed.get('score')}, issues={len(parsed.get('issues',[]))}")
|
|
for issue in parsed.get('issues', []):
|
|
orig = issue.get('original', '')
|
|
has_left = '左' in orig
|
|
has_right = '右' in orig
|
|
print(f" orig={repr(orig)}, hasLeft={has_left}, hasRight={has_right}")
|
|
if has_left:
|
|
print(f" -> 应高亮: '左'")
|
|
if has_right:
|
|
print(f" -> 应高亮: '右'")
|
|
except Exception as e:
|
|
print(f"解析失败: {e}")
|
|
|
|
# 移除代码块后的文本
|
|
clean = re.sub(r"```json[\s\S]*?```", "", raw).strip()
|
|
print(f"\n=== 清理后文本 ===")
|
|
print(clean)
|
|
|