Here you can find the source of camelCaseOrSpaceToDashed(String s)
public static String camelCaseOrSpaceToDashed(String s)
//package com.java2s; //License from project: Apache License public class Main { public static String camelCaseOrSpaceToDashed(String s) { // String dashed = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,s); // String trimmed = StringUtils.replace(StringUtils.replace(StringUtils.replace(dashed, " -", "-"), "- ", "-"), " ", "-"); ///*from ww w . j a va 2 s . c o m*/ // return trimmed.toLowerCase(); String trimmed = s.replaceAll("[\\s]", ""); String dashed = trimmed.replaceAll(String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z])", "(?<=[^A-Z])(?=[A-Z])", "(?<=[A-Za-z])(?=[^A-Za-z])"), "-"); dashed = dashed.replaceAll("--", "-"); return dashed.toLowerCase(); } }