Originally posted by Eugene Kanshin: Hello! I'm trying to replace all whitespaces in a string with underlines with: String str; str.replaceAll("\s+", "_"); but I've got illegal escape character error. Why it doesn't work?
The escape symbol in Java is \. In order to pass the parameter correctly to the replaceAll method, you need to pass \s, so you'll need to escape the escape character.