我有一个像这样的String数组
String str="9790020760001613 JOHN MATHEWS -66822.60 65000.00 69000.00 -1822.60 KARL MAX";
String[] token = str.split("\\s+");
我想连接所有非数字标记(例如JOHN MATHEWS),直到非数字标记后面紧跟数字字符串,以便上面的标记字符串数组看起来像这样:
[9790020760001613 ,JOHN MATHEWS,-66822.60,65000.00,69000.00,-1822.60,KARL MAX]
答案 0 :(得分:1)
如果匹配器没问题:
Pattern pattern = Pattern.compile("((?:-)?([0-9]+(?:\\.)?[0-9]+))|([A-Z]([A-Z/]|\\s)+[A-Z])");
Matcher matcher = pattern.matcher("9790020760001613 JOHN MATHEWS S/O -66822.60 65000.00 69000.00 -1822.60 KARL MAX");
List<String> matches = new ArrayList<String>();
while (matcher.find()) {
matches.add(matcher.group());
}
System.out.println(Arrays.toString(matches.toArray()));
输出:
[9790020760001613, JOHN MATHEWS S/O, -66822.60, 65000.00, 69000.00, -1822.60, KARL MAX]
可能会有所改进但是有效。