Explorar el Código

fix: 修复Java Unicode转义编译错误

将正则中的 [ohzu] 拆分,避免 \u 被误解为 Unicode 转义:
- [ohzlwnt] 和单独的 \\u 分开处理
何文松 hace 4 semanas
padre
commit
34889abac9

+ 6 - 3
backend/parse-service/src/main/java/com/lingyue/parse/service/WordStructuredExtractionService.java

@@ -350,8 +350,9 @@ public class WordStructuredExtractionService {
         String result = text;
         
         // 移除 TOC 域代码头(支持多种格式)
-        // 格式: TOC \o "1-2" \h \z \u
-        result = result.replaceAll("TOC\\s*(\\\\[ohzu]\\s*(\"[^\"]*\")?\\s*)+", "");
+        // 格式: TOC \o "1-2" \h \z \u (注意: Java 中 \u 是 Unicode 转义,需要特殊处理)
+        result = result.replaceAll("TOC\\s*(\\\\[ohzlwnt]\\s*(\"[^\"]*\")?\\s*)+", "");
+        result = result.replaceAll("TOC\\s*(\\\\u\\s*(\"[^\"]*\")?\\s*)+", "");
         
         // 移除 HYPERLINK 域代码
         // 格式: HYPERLINK \l "_Toc176869144" 实际文本
@@ -372,7 +373,9 @@ public class WordStructuredExtractionService {
         result = result.replaceAll("PAGEREF\\s+\\S+\\s*(\\\\h)?\\s*\\d*", "");
         
         // 移除其他常见域代码标记(如 \l \o \h \z \u)
-        result = result.replaceAll("\\\\[lohzu]\\s*", "");
+        // 注意: Java 中 \u 是 Unicode 转义,需要分开处理
+        result = result.replaceAll("\\\\[lohzwnt]\\s*", "");
+        result = result.replaceAll("\\\\u\\s*", "");
         
         // 清理多余空格
         result = result.replaceAll("\\s+", " ").trim();