Java String Slugify toSlug(String input)

Here you can find the source of toSlug(String input)

Description

http://stackoverflow.com/questions/1657193/

License

LGPL

Parameter

Parameter Description
input a parameter

Declaration

public static String toSlug(String input) 

Method Source Code

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

import java.text.Normalizer;
import java.text.Normalizer.Form;
import java.util.Locale;
import java.util.regex.Pattern;

public class Main {
    private static final Pattern NONLATIN = Pattern.compile("[^\\w-]");
    private static final Pattern WHITESPACE = Pattern.compile("[\\s]");

    /**//from   w  w  w . j  av a  2s  . c om
     * http://stackoverflow.com/questions/1657193/
     * @param input
     * @return
     */
    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);
    }
}

Related

  1. slugify(final String s)
  2. slugify(String input)
  3. slugify(String input)
  4. slugify(String s)
  5. toSlug(final String input)
  6. toSlug(String input)
  7. toSlug(String s)