我的猜测是,您缺少Java字符串文字中的反斜杠(’')字符是转义字符的情况。因此,当您想在以Java
String形式编写的正则表达式中使用’'转义符时,需要对其进行转义。例如
Pattern.compile("."); // Java syntax error// A regex that matches a (any) characterPattern.compile(".");// A regex that matches a literal '.' characterPattern.compile("\.");// A regex that matches a literal '' followed by one characterPattern.compile("\\.");该
String.split(StringseparatorRegex)方法将String拆分为多个子字符串,这些子字符串由与正则表达式匹配的子字符串分隔。因此,
str.split("\.")将拆分str为由单个文字“。”分隔的子字符串。字符。



