有一字符串str可能为100 days, 20 hours, 18 minutes, 27 seconds
也可能是20 hours, 18 minutes, 27 seconds
也可能是18 minutes, 27 seconds
也可能是27 seconds现求一个正则表达式获取这个字符串的数字.
请高手作答?
也可能是20 hours, 18 minutes, 27 seconds
也可能是18 minutes, 27 seconds
也可能是27 seconds现求一个正则表达式获取这个字符串的数字.
请高手作答?
String s = "100 days, 20 hours, 18 minutes, 27 seconds";
String a = "[a-zA-Z]*";
System.out.println(s.replaceAll(a, ""));
}
结果:100 , 20 , 18 , 27
public static void main(String[] args) {
String str = "100 days, 20 hours, 18 minutes, 27 seconds";
String reg = "(\\d+)";
Matcher matcher = Pattern.compile(reg).matcher(str);
while(matcher.find()){
System.out.println(matcher.group());
}
}