Java Utililty Methods String Slugify

List of utility methods to do String Slugify

Description

The list of methods to do String Slugify are organized into topic(s).

Method

Stringslugify(final String s)
slugify
final String intermediateResult = Normalizer.normalize(s, Normalizer.Form.NFD)
        .replaceAll("[^\\p{ASCII}]", "").replaceAll("[^-_a-zA-Z0-9]", "-").replaceAll("\\s+", "-")
        .replaceAll("[-]+", "-").replaceAll("^-", "").replaceAll("-$", "").toLowerCase();
return intermediateResult.substring(0, Math.min(MAX_SLUG_LENGTH, intermediateResult.length()));
Stringslugify(final String s)
slugify
return Normalizer.normalize(s, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "")
        .replaceAll("[^\\w+]", "-").replaceAll("\\s+", "-").replaceAll("[-]+", "-").replaceAll("^-", "")
        .replaceAll("-$", "").toLowerCase();
Stringslugify(String input)
slugify
if (input == null)
    return "";
String nowhitespace = WHITESPACE.matcher(input).replaceAll("-");
String normalized = Normalizer.normalize(nowhitespace, Form.NFD);
String slug = NONLATIN.matcher(normalized).replaceAll("");
return slug.toLowerCase(Locale.ENGLISH).replaceAll("--+", "-");
Stringslugify(String input)
Converts the string into a string containing only hyphens, lower-case letters, and numbers, removing all other characters.
String nowhitespace = WHITESPACE.matcher(input).replaceAll("-");
String normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD);
String slug = MULTIHYPHENS.matcher(NONLATIN.matcher(normalized).replaceAll("-")).replaceAll("-");
return slug.toLowerCase(Locale.ENGLISH);
Stringslugify(String s)
slugify
if (s == null)
    return null;
if (s.isEmpty())
    return s;
String result = Normalizer.normalize(s, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "");
result = result.replace(" ", "-");
result = result.toLowerCase();
return result;
...
StringtoSlug(final String input)
Convert the String input to a slug.
if (input == null) {
    throw new IllegalArgumentException("Input cannot be null");
final Pattern NONLATIN = Pattern.compile("[^\\w-]");
final Pattern WHITESPACE = Pattern.compile("[\\s]");
String nowhitespace = WHITESPACE.matcher(input).replaceAll("-");
String normalized = Normalizer.normalize(nowhitespace, Form.NFD);
String slug = NONLATIN.matcher(normalized).replaceAll("");
...
StringtoSlug(String input)
http://stackoverflow.com/questions/1657193/
String nowhitespace = WHITESPACE.matcher(input).replaceAll("-");
String normalized = Normalizer.normalize(nowhitespace, Form.NFD);
String slug = NONLATIN.matcher(normalized).replaceAll("");
return slug.toLowerCase(Locale.ENGLISH);
StringtoSlug(String input)
Convert the String input to a slug.
if (input == null) {
    throw new IllegalArgumentException("Input cannot be null");
String nowhitespace = WHITESPACE.matcher(input).replaceAll("-");
String normalized = Normalizer.normalize(nowhitespace, Form.NFD);
String slug = NONLATIN.matcher(normalized).replaceAll("");
return slug.toLowerCase(Locale.ENGLISH);
StringtoSlug(String s)
to Slug
s = Normalizer.normalize(s, Normalizer.Form.NFD);
s = s.replaceAll("\\.", "-");
s = s.replaceAll(":", "-");
s = s.replaceAll("\\s+", "-");
s = s.replaceAll("[^\\p{ASCII}]", "");
s = s.replaceAll("[^a-zA-Z0-9- ]", "");
s = s.toLowerCase();
s = s.replaceAll("--", "-");
...