regex - replace underscore lowercase with uppercase

前端 未结 4 571
误落风尘
误落风尘 2021-01-17 22:36

I\'ve wondering is there a regex pattern that i could use to convert a pattern which is an underscore and a lowercase letter into an uppercase letter. I\'m trying to generat

4条回答
  •  时光说笑
    2021-01-17 23:23

    You can use:

    String s = "load_id,policy_id,policy_number";
    Pattern p = Pattern.compile( "_([a-zA-Z])" );
    Matcher m = p.matcher( s );
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        m.appendReplacement(sb, m.group(1).toUpperCase());
    }
    m.appendTail(sb);
    System.out.println(sb.toString()); // loadId,policyId,policyNumber
    

提交回复
热议问题