import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^\\}\\R(?=[A-Z])";
final String string = "I(0,123...789){\n"
+ "A(0,567...999){.......n=Marc.....}\n"
+ "B(2,655...265){..................}\n"
+ "C(3,993...333){..................}\n"
+ "M(8,635...254){.................;}\n"
+ "}\n"
+ "O(0,345...789){\n"
+ "A(0,567...999){.......n=Marc.....}\n"
+ "B(2,876...775){..................}\n"
+ "C(3,993...549){..................}\n"
+ "M(8,354...987){.................;}\n"
+ "}\n"
+ "I(0,987...764){\n"
+ "A(0,567...999){.......n=Marc.....}\n"
+ "B(2,543...265){..................}\n"
+ "C(7,998...933){..................}\n"
+ "M(8,645...284){.................;}\n"
+ "}\n"
+ "B(0,123...789){\n"
+ ".......\n"
+ "}\n"
+ "I(0,987...764){\n"
+ "A(0,567...999){.......n=John.....}\n"
+ "B(2,543...265){..................}\n"
+ "C(7,998...933){..................}\n"
+ "M(8,645...284){.................;}\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