我有一个字符串如下
Esophageal have not 45.3
The end is nigh 23
Maybe (just) (maybe>32) 45.2
每一行都以数字结尾(包含小数点和不包含小数点) 我想在最后一个数字
之前拆分该行我试过这个正则表达式:
myarray[]=null;
myarray=match.split("/\\s+(?=\\S*+$)/");
但它没有拆分
答案 0 :(得分:1)
您可以使用此
String Str = "Maybe (just) (maybe>32) 45.2";
for (String retval: Str.split("\\s(?=\\b(\\d+(?:\\.\\d+)?)$)")){
System.out.println(retval);
}
<强> Ideone Demo 强>
答案 1 :(得分: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);
答案 2 :(得分:0)
match.split("[ \\t](?=[.\\d]+([\\n\\r]+|$))");
结果应该如下:
Esophageal have not
45.3 The end is nigh
23 Maybe (just) (maybe>32)
45.2