字符串为
10-30 03:45:04.312 2760 2760 GrowthKit: job GrowthKit.PeriodicSyncJob E
所以输出应该如下所示
10-30
03:45:04.312
2760
2760
GrowthKit: job GrowthKit.PeriodicSyncJob failed
E
需要使用正则表达式匹配器和模式来完成。
书面代码:
public static void main(String[] args) {
String s = "10-30 03:45:04.312 2760 2760 GrowthKit: job GrowthKit.PeriodicSyncJob E ";
Pattern regex = Pattern.compile("^([a-zA-Z0-9]+).*");
Matcher matcher = regex.matcher(s);
while (matcher.find()) {
for (int i = 0; i < matcher.groupCount(); i++) {
String[] words = matcher.group(i).split("\\s+");
for (String line : words) {
System.out.println("" + line);
}
}
}
}
请为我们提供解决方案:
幕布斯7119047
ibeautiful
慕沐林林
随时随地看视频慕课网APP
相关分类