import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=3\\. Induction Training\\n).*(?=4\\. Corporate Training\\/Departmental Training)";
final String string = "3. Induction Training\n"
+ "3.1. Line managers should assess the training needs of all new staff to their department in order to help them perform to a satisfactory standard from the outset. 3.2. They should design a departmental induction programme to meet the specific needs of individual starters, together with the Corporate Induction programme which must be attended by all new employees to the City & County of Swansea. 3.3. Newly promoted staff should also have an individual training plan in order to prepare them for their new roles and responsibilities; this should also include colleagues appointed to a supervisory/management role.\n"
+ "4. Corporate Training/Departmental Training";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
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