就是aa_bb_cc转成aaBbCc

解决方案 »

  1.   


    //package com.ricky.www;
    /*
     就是aa_bb_cc转成aaBbCc
    */
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Test{
    public static void main(String[] args){
    String content = "aa_bb_cc";
    String result = replace(content);
    System.out.println(result);
    } public static String replace(String content){
    String result = content;
    String regex = "(\\w)(\\1)(_(\\w)(\\4))+?";
    Pattern pattern = Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(content);
    while(matcher.find()){
    result = matcher.replaceAll(matcher.group(1) + matcher.group(2) + matcher.group(4).toUpperCase() + matcher.group(4));
    matcher = pattern.matcher(result);
    }
    return result;
    }
    }