Created
April 24, 2014 09:17
-
-
Save nurv/11247778 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String slugify(String name) { | |
Pattern NONLATIN = Pattern.compile("[^\\w-]"); | |
Pattern WHITESPACE = Pattern.compile("[\\s]"); | |
name = name.trim(); | |
name = Normalizer.normalize(name, Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); | |
String nowhitespace = WHITESPACE.matcher(name).replaceAll("-"); | |
String normalized = Normalizer.normalize(nowhitespace, Form.NFD); | |
String slug = NONLATIN.matcher(normalized).replaceAll(""); | |
name = slug.toLowerCase(Locale.ENGLISH); | |
return name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment