public static String underscore ( String word ) { String firstPattern = "([A-Z]+)([A-Z][a-z])" ; String secondPattern = "([a-z\\d])([A-Z])" ; String replacementPattern = "$1_$2" ; // Replace package separator with slash. word = word . replaceAll ( "\\." , "/" ) ; // Replace $ with two underscores for inner classes. word = word . replaceAll ( "\\$" , "__" ) ; // Replace capital letter with _ plus lowercase letter. word = word . replaceAll ( firstPattern , replacementPattern ) ; word = word . replaceAll ( secondPattern , replacementPattern ) ; word = word . replace ( ' ' , ' ' ) ; word = word . toLowerCase ( ) ; return word ; }
Underscore the given word .