曾经用过的正则表达式

public static void main(String[] args) {
  String aString="w14-rq22.3";
  //只保留数字
  aString = aString.replaceAll("[^(0-9)]","");
  System.out.println(aString);
  String bString="w14-rq22.3";
  //保留数字,小数点
  bString = bString.replaceAll("[^\\d.]", "");
  System.out.println(bString);
  String cString="w14-rq22.3";
  //保留数字,小数点,负号
  cString = cString.replaceAll("[^\\d.\\d-]", "");
  System.out.println(cString);
}

相关推荐