converts ruby to camel case by regex - Java java.lang

Java examples for java.lang:String Camel Case

Description

converts ruby to camel case by regex

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String camelCase = "java2s.com";
        System.out.println(camelToSnakeCase(camelCase));
    }/*from w ww.  j  a  v a 2s.com*/

    /**
     * converts ruby to camel case
     */
    public static String camelToSnakeCase(final String camelCase) {
        // check for null
        if (camelCase == null || camelCase.isEmpty()) {
            return "";
        }

        // simple regex
        return camelCase.replaceAll("\\B([A-Z])", "_$1").toLowerCase();
    }
}

Related Tutorials