Community
Participate
Working Groups
This should replace all spaces in s with colons, and save the result in t: String s = "a b c"; String t = s.replaceAll("\s", ":"); Eclipse does not allow this to build, reporting: Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\) Or is this a Java compiler error? String.replaceAll, replaceFirst, split, and java.util.regex.Pattern.compile all use special escape sequence like \s to denote character classes; these are unusable with this bug. Workaround: use the explicit character class, e.g., "[ \t\n\f\r]" instead of "\s". Desired fix: make "Use of non-standard character class" a Style or Advanced option in the Java compiler properties dialog, with the standard Ignore/Warning/Error choices. Perhaps suppress this complaint automatically for methods known to use regex escapes.
Compiler behavior looks correct. Rewrite the snippet as follows: String t = s.replaceAll("\\s", ":");
Compiler behavior is ok. Please rewrite your code as suggested by John. Closing.