java正则表达式高级用法:转换驼峰标示


String source = "LastLoginIp";
String regexStr = "[A-Z]";
Matcher matcher = Pattern.compile(regexStr).matcher(source);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String g = matcher.group();
matcher.appendReplacement(sb, "_" + g.toLowerCase());
}
matcher.appendTail(sb);
if (sb.charAt(0) == '_') {
sb.delete(0, 1);
}
System.out.println(sb.toString());

你可能感兴趣的:(java)