2016-05-31 15 views
-1

标签的空间,我有一个字符串如下斯普利特最后空间,包括在Java

Esophageal have not 45.3 
The end is nigh 23 
Maybe (just) (maybe>32) 45.2 

的编号每行结束(带或不带小数点) 我想最后一个数字之前分割线

我已经试过此正则表达式:

myarray[]=null; 
    myarray=match.split("/\\s+(?=\\S*+$)/"); 

,但它不拆呢

+0

删除正则表达式分隔符。使用'“\\ s +(?= \\ S * + $)”'。参见[demo](http://ideone.com/gdVDPZ)。 –

+1

不要尝试分割,尝试匹配(使用匹配或使用捕获组的查找方法)。 –

+0

什么是您正在等待的确切输出? – Raptor

回答

1

您可以使用此

String Str = "Maybe (just) (maybe>32) 45.2"; 

for (String retval: Str.split("\\s(?=\\b(\\d+(?:\\.\\d+)?)$)")){ 
    System.out.println(retval); 
} 

Ideone Demo

0

就分割字符串并获得数组的最后一个值:

String[] array = "Maybe (just) (maybe>32) 45.2".split(" "); 
    String firstPart = array[0]; 
    String lastPart = array[array.length-1]; 
    for (int i = 1; i < array.length - 1; i++) { 
     firstPart += " " + array[i]; 
    } 

    System.out.println(firstPart); 
    System.out.println(lastPart); 
0
match.split("[ \\t](?=[.\\d]+([\\n\\r]+|$))"); 

结果应该是这样的:

Esophageal have not 
45.3 The end is nigh 
23 Maybe (just) (maybe>32) 
45.2