/* 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 ptrn = Pattern.compile(pattern1); Matcher matcher = ptrn.matcher(value1); ArrayList<ArrayList<String>> result_lst = new ArrayList<ArrayList<String>>(); ArrayList<String> lst = null; while (matcher.find()) { if (!matcher.group(1).equals("")) { if (lst != null) result_lst.add(lst); lst = new ArrayList<String>(); lst.add(matcher.group(1)); } else { lst.add(matcher.group(2)); } } if (lst != null) result_lst.add(lst); } }
Standard input is empty