/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.util.regex.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { Pattern pattern = Pattern.compile("(?<tabledata>\\S+)\\s+\\S+(?<vals>[|\\d\\s]+)"); Matcher matcher = pattern.matcher(s); List<List<String>> res = new ArrayList<>(); while (matcher.find()){ List<String> lst = new ArrayList<>(); if (matcher.group("tabledata") != null) { lst.add(matcher.group("tabledata")); } if (matcher.group("vals") != null) { Matcher m = Pattern.compile("\\d+").matcher(matcher.group("vals")); while (m.find()) { lst.add(m.group(0)); } } res.add(lst); } } }
Standard input is empty