日期:2014-05-17 浏览次数:20789 次
public static void main(String[] args) { String s = "-北京 2.4 1.3 12.34534 0.123 -上海 3.1 0 0 12.345 2.1"; Pattern p = Pattern.compile("(\\s\\d+(\\.\\d+)?){4}"); Matcher m = p.matcher(s); while(m.find()) { int start = m.start(); int end = m.end(); System.out.println(s.substring(start-2,start)); String[] strs = s.substring(start, end).trim().split("\\s"); for(String s1:strs) { System.out.println(s1); } } }