我收到此字符串的无效转义序列错误。如何在我的 java 代码中转义它?
"^(?:(2\d\d\d)\s+)?(?:Comm\. Rep\.\s+)?(?:CONG\s+)?(\S+)\s+(\S+)\s+(?:No\.\s+)?(\S+)(?:\s+\(.*?\))?$"
反斜杠 ( \
) 本身必须转义:
"^(?:(2\\d\\d\\d)\\s+)?(?:Comm\\. Rep\\.\\s+)?(?:CONG\\s+)?(\\S+)\\s+(\\S+)\\s+(?:No\\.\\s+)?(\\S+)(?:\\s+\\(.*?\\))?$"