您需要使用
Pattern.DOTALL标志来表示点应与换行符匹配。例如
Pattern.compile(regex, Pattern.DOTALL).matcher(testIllegal).replaceAll("x")或者使用
(?s)例如在模式中指定标志
String regex = "(?s)\s*/\*.*\*/";

您需要使用
Pattern.DOTALL标志来表示点应与换行符匹配。例如
Pattern.compile(regex, Pattern.DOTALL).matcher(testIllegal).replaceAll("x")或者使用
(?s)例如在模式中指定标志
String regex = "(?s)\s*/\*.*\*/";