将字符串中的汉字去掉只保留数字

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);

    }
}

输出结果:6

猜你喜欢

转载自my.oschina.net/u/2301293/blog/2051553