import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=TITLE)(?!\\s*Direct Submission)[\\S\\s]*?(?=JOURNAL)";
final String string = " TITLE The Identification of Novel Diagnostic Marker Genes for the\n"
+ " Detection of Beer Spoiling Pediococcus damnosus Strains Using the\n"
+ " BlAst Diagnostic Gene findEr\n"
+ " JOURNAL PLoS One 11 (3), e0152747 (2016)\n"
+ " PUBMED 27028007\n"
+ " REMARK Publication Status: Online-Only\n"
+ "REFERENCE 2 (bases 1 to 462)\n"
+ " AUTHORS Behr,J., Geissler,A.J. and Vogel,R.F.\n"
+ " TITLE Direct Submission\n"
+ " JOURNAL Submitted (04-AUG-2015) Technische Mikrobiologie, Technische\n"
+ " TITLE OtherDirect Submission\n"
+ " JOURNAL Submitted (04-AUG-2015) Technische Mikrobiologie, Technische";
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