Java code/library for generating slugs (for use in pretty URLs)
Normalize your string using canonical decomposition: private static final Pattern NONLATIN = Pattern.compile(“[^\\w-]”); private static final Pattern WHITESPACE = Pattern.compile(“[\\s]”); public static String toSlug(String input) { String nowhitespace = WHITESPACE.matcher(input).replaceAll(“-“); String normalized = Normalizer.normalize(nowhitespace, Form.NFD); String slug = NONLATIN.matcher(normalized).replaceAll(“”); return slug.toLowerCase(Locale.ENGLISH); } This is still a fairly naive process, though. It isn’t going to do … Read more