@Test public void shouldReplaceMultipleWhitespaceWithASingleSpace() { String text = " White\t \t spaces\t are replaced "; String normalisedText = StringNormaliser.normalise(text); Assert.assertEquals("White spaces are replaced", normalisedText); }
public static String normalise(String text) { return text.trim().replaceAll("\\p{Pd}", "-").replaceAll("\\r", " ").replaceAll("\\n", " ").replaceAll("\\s+", " ") .replaceAll("[^\\x20-\\x7e]", ""); }
StringNormaliser { public static String normalise(String text) { return text.trim().replaceAll("\\p{Pd}", "-").replaceAll("\\r", " ").replaceAll("\\n", " ").replaceAll("\\s+", " ") .replaceAll("[^\\x20-\\x7e]", ""); } }
StringNormaliser { public static String normalise(String text) { return text.trim().replaceAll("\\p{Pd}", "-").replaceAll("\\r", " ").replaceAll("\\n", " ").replaceAll("\\s+", " ") .replaceAll("[^\\x20-\\x7e]", ""); } private  StringNormaliser(); }
StringNormaliser { public static String normalise(String text) { return text.trim().replaceAll("\\p{Pd}", "-").replaceAll("\\r", " ").replaceAll("\\n", " ").replaceAll("\\s+", " ") .replaceAll("[^\\x20-\\x7e]", ""); } private  StringNormaliser(); static String normalise(String text); }
StringNormaliser { public static String normalise(String text) { return text.trim().replaceAll("\\p{Pd}", "-").replaceAll("\\r", " ").replaceAll("\\n", " ").replaceAll("\\s+", " ") .replaceAll("[^\\x20-\\x7e]", ""); } private  StringNormaliser(); static String normalise(String text);  }