Java String Slugify slugify(final String s)

Here you can find the source of slugify(final String s)

Description

slugify

License

Apache License

Declaration

public static String slugify(final String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.Normalizer;

public class Main {
    private static final int MAX_SLUG_LENGTH = 256;

    public static String slugify(final String s) {
        //algorithm used in https://github.com/slugify/slugify/blob/master/core/src/main/java/com/github/slugify/Slugify.java
        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()));
    }//ww  w.j  a v  a  2  s. c  om
}

Related

  1. slugify(final String s)
  2. slugify(String input)
  3. slugify(String input)
  4. slugify(String s)