/**
* 使用正则表达式过滤非数字字符串
* @param str 需要过滤的字符串
* @return
*/
public static String filterUnNumber(String str) {
// 只允数字
String regEx = "[^0-9]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
//把非数字的字符替换为""
return m.replaceAll("").trim();
}
* 使用正则表达式过滤非数字字符串
* @param str 需要过滤的字符串
* @return
*/
public static String filterUnNumber(String str) {
// 只允数字
String regEx = "[^0-9]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
//把非数字的字符替换为""
return m.replaceAll("").trim();
}