java正則,將


java正則,將<a或者</a,尖括號后面的字母改成大寫

/**
     * 將<a或者</a中的a,轉為大寫字母
     * @param xmlStr
     * @return
     */
    public static String firstLabelToUppper(String xmlStr){
        Pattern p = Pattern.compile("\\<[a-z|A-Z]");
        Matcher m = p.matcher(xmlStr);
        StringBuffer sb = new StringBuffer();
        while (m.find())
        { // Find each match in turn; String can't do this.
//String name = m.group(1); // Access a submatch group; String can't do this.
            m.appendReplacement(sb,  m.group().toUpperCase());
           // System.out.println("m.group() is= " + m.group());
        }
        m.appendTail(sb);
        //System.out.println("sb is= " + sb);

        return lastLabelToUppper(sb.toString());
    }

    /**
     * 將<a或者</a中的a,轉為大寫字母
     * @param xmlStr
     * @return
     */
    public static String lastLabelToUppper(String xmlStr){
        Pattern p = Pattern.compile("\\</[a-z|A-Z]");
        Matcher m = p.matcher(xmlStr);
        StringBuffer sb = new StringBuffer();
        while (m.find())
        { // Find each match in turn; String can't do this.
//String name = m.group(1); // Access a submatch group; String can't do this.
            m.appendReplacement(sb,  m.group().toUpperCase());
            //System.out.println("m.group() is= " + m.group());
        }
        m.appendTail(sb);
        //System.out.println("sb is= " + sb);

        return sb.toString();
    }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM