更新时间:2023-02-26 12:31:15
只需使用:
text.replaceAll([\\\\]] * [0-9。 ] + [\\w] *,\ n);
它用一个替换所有数字字符和点换行符,所以如果你把结果放到JTextArea,每个名字都在一行上。
It replaces all numeric characters and dots with a newline character, so if you put the result to a JTextArea, every name will be on a single line.
要获得数字之间的字符串,请使用split()方法。
To get the Strings between the numbers, use the split() method.
String[] names = text.split("[\\w]*[0-9.]+[\\w]*");
正则表达式现在还删除了数字和名称之间的空格。 String [] names
将包含单个名称。
The regex now also removes whitespaces between the numbers and the names. String[] names
will contain the single names.