import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\* LIST \\((?<Markers>.*)\\) \\\"\\/\\\" (?<folder>.*?)$";
final String string = "* LIST (\\HasChildren) \"/\" INBOX/Arkabit\n"
+ "* LIST (\\HasNoChildren) \"/\" \"INBOX/Arkabit/Flora (SAP)\"\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/BRW\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Chiptronics\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/CRMB1.COM\n"
+ "* LIST (\\Marked \\HasChildren) \"/\" INBOX/CVA\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/CVA/Contabilista\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/CVA/Maxflex\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Decorlux\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Fabiano\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Fabielle\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Gamma\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Integrate\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Kelli\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Laborclin\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Macrosul\n"
+ "* LIST (\\HasChildren) \"/\" INBOX/MadeiraMadeira\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/MadeiraMadeira/BRW\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/MadeiraMadeira/Eglo\n"
+ "* LIST (\\HasNoChildren) \"/\" \"INBOX/MadeiraMadeira/Full Fit\"\n"
+ "* LIST (\\HasNoChildren) \"/\" \"INBOX/MadeiraMadeira/Glass Mosaic\"\n"
+ "* LIST (\\Marked \\HasNoChildren) \"/\" INBOX/MadeiraMadeira/Luciin\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/MadeiraMadeira/Rojemac\n"
+ "* LIST (\\HasNoChildren) \"/\" \"INBOX/Mercado do Alarme\"\n"
+ "* LIST (\\Marked \\HasChildren) \"/\" INBOX/Stuff\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Stuff/Importado\n"
+ "* LIST (\\Marked \\HasNoChildren) \"/\" INBOX/Stuff/Ita&APo-\n"
+ "* LIST (\\Marked \\HasNoChildren) \"/\" INBOX/Stuff/Literal\n"
+ "* LIST (\\HasChildren) \"/\" INBOX/Stuff/News\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Stuff/News/Linkedin\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Stuff/News/Microsoft\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Stuff/News/SAP\n"
+ "* LIST (\\Marked \\HasNoChildren) \"/\" INBOX/Stuff/Postman\n"
+ "* LIST (\\HasChildren) \"/\" INBOX/Stuff/PrimaERP\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Stuff/PrimaERP/Faturas\n"
+ "* LIST (\\Marked \\HasNoChildren) \"/\" INBOX/Stuff/VSOnline\n"
+ "* LIST (\\HasNoChildren) \"/\" \"INBOX/Suporte | CRMSAP\"\n"
+ "* LIST (\\HasNoChildren) \"/\" INBOX/Umbler\n"
+ "$ OK LIST completed.\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html