Skip to content

Instantly share code, notes, and snippets.

@hperantunes
Created March 2, 2017 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hperantunes/9634dc7bf23f4283d2deda679274de8e to your computer and use it in GitHub Desktop.
Save hperantunes/9634dc7bf23f4283d2deda679274de8e to your computer and use it in GitHub Desktop.
// Newlines, tabs and non-printable unicode characters
private static final String sanitizePattern = "(\\r|\\n|\\t|\\p{C})";
private static final String whitespacePattern = " +";
private static final String replacementString = " ";
private static String sanitize(String text) {
return text.replaceAll(sanitizePattern, replacementString);
}
private static String normalizeWhitespace(String text) {
return text.replaceAll(whitespacePattern, replacementString);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment