標籤的空間,我有一個字符串如下斯普利特最後空間,包括在Java
Esophageal have not 45.3
The end is nigh 23
Maybe (just) (maybe>32) 45.2
的編號每行結束(帶或不帶小數點) 我想最後一個數字之前分割線
我已經試過此正則表達式:
myarray[]=null;
myarray=match.split("/\\s+(?=\\S*+$)/");
,但它不拆呢
標籤的空間,我有一個字符串如下斯普利特最後空間,包括在Java
Esophageal have not 45.3
The end is nigh 23
Maybe (just) (maybe>32) 45.2
的編號每行結束(帶或不帶小數點) 我想最後一個數字之前分割線
我已經試過此正則表達式:
myarray[]=null;
myarray=match.split("/\\s+(?=\\S*+$)/");
,但它不拆呢
您可以使用此
String Str = "Maybe (just) (maybe>32) 45.2";
for (String retval: Str.split("\\s(?=\\b(\\d+(?:\\.\\d+)?)$)")){
System.out.println(retval);
}
就分割字符串並獲得數組的最後一個值:
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);
match.split("[ \\t](?=[.\\d]+([\\n\\r]+|$))");
結果應該是這樣的:
Esophageal have not
45.3 The end is nigh
23 Maybe (just) (maybe>32)
45.2
刪除正則表達式分隔符。使用'「\\ s +(?= \\ S * + $)」'。參見[demo](http://ideone.com/gdVDPZ)。 –
不要嘗試分割,嘗試匹配(使用匹配或使用捕獲組的查找方法)。 –
什麼是您正在等待的確切輸出? – Raptor