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正则表达式高级用法:转换驼峰标示
最新推荐文章于 2024-07-04 09:52:06 发布