Here you can find the source of snakify(String original)
public static String snakify(String original)
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String snakify(String original) { if (original == null || original.length() == 0) return ""; StringBuilder builder = new StringBuilder(); Pattern p = Pattern.compile("[A-Z][a-z0-9]+"); Matcher m = p.matcher(original); String word;//from w w w .j a va 2 s. co m while (m.find()) { word = m.group(); builder.append(word.toLowerCase()); if (!m.hitEnd()) { builder.append('_'); } } if (builder.length() == 0) { return original.toLowerCase(); } return builder.toString(); } }