package javaDemo; import java.util.regex.Matcher; import java.util.regex.Pattern; public class GetNumFromString { /** * @songwenju */ public static void main(String[] args) { String str = "Java教程12.50"; String regex = "\\d*[.]\\d*"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(str); while (m.find()) { if (!"".equals(m.group())) System.out.println("价格:" + m.group()); } } }
时间: 2024-10-10 12:58:40