camel Case To Dot Case by regex - Java java.lang

Java examples for java.lang:String Camel Case

Description

camel Case To Dot Case by regex

Demo Code


//package com.java2s;

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

    public static String camelCaseToDotCase(String name) {
        return name.replaceAll(
                String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z])",
                        "(?<=[^A-Z])(?=[A-Z])",
                        "(?<=[A-Za-z])(?=[^A-Za-z])"), ".").toLowerCase();
    }
}

Related Tutorials