Here you can find the source of toSlug(String input)
http://stackoverflow.com/questions/1657193/
Parameter | Description |
---|---|
input | a parameter |
public static String toSlug(String input)
//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); } }