我收到此字符串的无效转义序列错误。如何在我的java代码中逃避它?
"^(?:(2\d\d\d)\s+)?(?:Comm\. Rep\.\s+)?(?:CONG\s+)?(\S+)\s+(\S+)\s+(?:No\.\s+)?(\S+)(?:\s+\(.*?\))?$"
答案 0 :(得分:5)
反斜杠(\
)本身must可以转义:
"^(?:(2\\d\\d\\d)\\s+)?(?:Comm\\. Rep\\.\\s+)?(?:CONG\\s+)?(\\S+)\\s+(\\S+)\\s+(?:No\\.\\s+)?(\\S+)(?:\\s+\\(.*?\\))?$"