You need to use the Pattern.DOTALL
flag to say that the dot should match newlines. e.g.
Pattern.compile(regex, Pattern.DOTALL).matcher(testIllegal).replaceAll("x")
or alternatively specify the flag in the pattern using (?s)
e.g.
String regex = "(?s)\\s*/\\*.*\\*/";