java驼峰转下划线

Pattern pattern = Pattern.compile("\\B(\\p{Upper})(\\p{Lower}*)");
Matcher matcher = pattern.matcher("longAndLongCity");
String replaceAll = matcher.replaceAll("_$1$2");
String result = replaceAll.toLowerCase() // 不是很优美
System.out.println(result);

你可能感兴趣的:(java,正则)