將字符串中的漢字去掉只保留數字

import java.util.regex.Pattern;

/**
 * @Description: 將月份或字符串中的漢字去掉,只剩下數字。
 * @Author: ls  @Date: 17:05 17:05
 */
public class StringTrimAsNum {

    public static void main(String[] args) {
        String str = "1月";
        String str1 = "6月";
        String result = Pattern.compile("[^0-9]").matcher(str1).replaceAll("");
        System.out.println(result);

    }
}

輸出結果:6java

相關文章
相關標籤/搜索