System Benchs Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   18955468.4   1624.3
Double-Precision Whetstone                       55.0       2489.0    452.5
Execl Throughput                                 43.0       2033.8    473.0
File Copy 1024 bufsize 2000 maxblocks          3960.0     349619.4    882.9
File Copy 256 bufsize 500 maxblocks            1655.0      99537.8    601.4
File Copy 4096 bufsize 8000 maxblocks          5800.0     817542.9   1409.6
Pipe Throughput                               12440.0     900532.5    723.9
Pipe-based Context Switching                   4000.0     187964.4    469.9
Process Creation                                126.0       5752.6    456.6
Shell Scripts (1 concurrent)                     42.4       2518.2    593.9
Shell Scripts (8 concurrent)                      6.0        317.3    528.8
System Call Overhead                          15000.0    1253825.8    835.9
                                                                   ========
System Benchs Index Score                                         684.7
从这个输出中提取最后一行的684.7这个数,正则该怎么写哇?

解决方案 »

  1.   

    不用光靠正则吧,一行一行读取进来,判断是否为最后一行的开始,如果是则进行处理,比如:
    if (line.startsWith("System Benchs")) {
      String tmp = line.replaceAll("[a-zA-Z]|\\s", "");
      double num = Double.valueOf(tmp);
    }
      

  2.   

    这段文字是一个字符串还是什么?
    for example
    String s = "System Call Overhead 15000.0 1253825.8 835.9\n"
             + "========\n"
             + "System Benchs Index Score 684.7";
    String[] sa = s.split("\n");
    Pattern p = "\\d+([.]\\d+)?";
    Matcher m = p.macher(sa[sa.length-1]);
    while (m.find()) {
        System.out.println(m.group());
    }
      

  3.   

    如果你能确定最后一行,那么很简单的,你spilt("\\s")后取最后一段就可以了吧。