//将异常的字符串转化为整数
public static Integer abnormalTextToInt(String text, Integer defaultValue) {
try {
return Integer.parseInt(Pattern.compile("[^0-9]").matcher(text).replaceAll("").trim());
} catch (Exception e) {
return defaultValue;
}
}
【Java】【正则表达式】去除字符串中的非数字字符
关注
打赏