小程序:使用正则表达式去除字符串中的非数字元素

来源:互联网 发布:mysql 表连接 编辑:程序博客网 时间:2024/06/06 21:39

/**
 * 使用正则表达式去除字符串中的非数字元素
 *使用替换方法
 */
public class NumberPattern {


public static void main(String[] args) {
String result=replace("2010-5-24 10:53:30");
System.out.println(result);
}
//把字符串中非数字删除
public static String replace(String text){
return text.replaceAll("\\D+", "");//把非数字替换为空值;
}
}
0 0