1

这是文本行:

003 STATE BANK OF BIK & JAI A/C.1 2 1,01,500.00 1 3,160.00 98,340.00+

这是我的代码片段来拆分它:

Pattern pat = Pattern.compile("[ ]");
String strs[] = pat.split(s);
for (int i = 0; i < strs.length; i++) {
    System.out.println("Next Token = " + strs[i]);
}

这是我得到的:

003,STATE,BANK,OF,BIK,*,JAI...etc.

我真正想要的是:

003,STATE BANK OF BIK & JAI,A/C.1,2.1,01,500.00...etc

我使用哪种模式或元字符来完成此操作?

4

1 回答 1

0

对于您的情况,此拆分呼叫将起作用:

String data = "003 STATE BANK OF BIK & JAI A/C.1 2 1,01,500.00 1 3,160.00 98,340.00+";
String[] arr = data.split(" +(?=\\S*\\d)|(?<![A-Z&]) +");
System.out.println(Arrays.toString(arr));

输出:

[003, STATE BANK OF BIK & JAI, A/C.1, 2, 1,01,500.00, 1, 3,160.00, 98,340.00+]
于 2013-10-13T05:55:34.407 回答