数值类截取
1、提取字符串中的指定字符后的首个数字
public static void main(String[] args) {
String text1 = "大小约:1389173cm,dana";
Pattern p = Pattern.compile("大小\\D+(\\d)");
Matcher m = p.matcher(text1);
String fz = "";
if(m.find()){
fz = m.group(1);
}
System.out.println("============"+fz);
}
上面的代码就可以获取到数字“1”
2、提取字符串中的指定字符后的首个数值
public static void main(String[] args) {
String text1 = "大小约:1.3cm89173cm,dana";
Pattern p = Pattern.compile("大小\\D+(\\d+(?:\\.\\d+)?)cm");
Matcher m = p.matcher(text1);
String fz = "";
if(m.find()){
fz = m.group(1);
}
System.out.println("============"+fz);
}
}
上面的代码就可以获取到数值“1.3”