import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?m)^\\s*\\d+\\..*\\R{2} # Get to the title\n"
+ "(?<title>[^\\n]*(?:\\n(?!\\n)[^\\n]*)*) # Get title\n"
+ "\\R{2} # Get to the authors\n"
+ "[^\\n]*(?:\\n(?!\\R)[^\\R]*)* # Consume authors\n"
+ "(?<abstract>[^\\[]*(?:\\[(?!PubMed[ ]-[ ]indexed[ ]for[ ]MEDLINE\\])[^\\[]*)*) # Grab abstract";
final String string = "1. Br J Biomed Sci. 2015;72(3):93-101.\n\n"
+ "Effects of propofol and isoflurane on haemodynamics and the inflammatory response\n"
+ "in cardiopulmonary bypass surgery.\n\n"
+ "Sayed S, Idriss NK, Sayyedf HG, Ashry AA, Rafatt DM, Mohamed AO, Blann AD.\n\n"
+ "Cardiopulmonary bypass (CPB) causes reperfusion injury that when most severe is\n"
+ "clinically manifested as a systemic inflammatory response syndrome. The\n"
+ "anaesthetic propofol may have anti-inflammatory properties that may reduce such a\n"
+ "response. We hypothesised differing effects of propofol and isoflurane on\n"
+ "inflammatory markers in patients having CBR Forty patients undergoing elective\n"
+ "CPB were randomised to receive either propofol or isoflurane for maintenance of\n"
+ "anaesthesia. CRP, IL-6, IL-8, HIF-1α (ELISA), CD11 and CD18 expression (flow\n"
+ "cytometry), and haemoxygenase (HO-1) promoter polymorphisms (PCR/electrophoresis)\n"
+ "were measured before anaesthetic induction, 4 hours post-CPB, and 24 hours later.\n"
+ "There were no differences in the 4 hours changes in CRP, IL-6, IL-8 or CD18\n"
+ "between the two groups, but those in the propofol group had higher HIF-1α (P =\n"
+ "0.016) and lower CD11 expression (P = 0.026). After 24 hours, compared to the\n"
+ "isoflurane group, the propofol group had significantly lower levels of CRP (P <\n"
+ "0.001), IL-6 (P < 0.001) and IL-8 (P < 0.001), with higher levels CD11 (P =\n"
+ "0.009) and CD18 (P = 0.002) expression. After 24 hours, patients on propofol had \n"
+ "increased expression of shorter HO-1 GT(n) repeats than patients on isoflurane (P\n"
+ "= 0.001). Use of propofol in CPB is associated with a less adverse inflammatory\n"
+ "profile than is isofluorane, and an increased up-regulation of HO-1. This\n"
+ "supports the hypothesis that propofol has anti-inflammatory activity.\n\n"
+ "PMID: 26510263 [PubMed - indexed for MEDLINE]\n"
+ "11. Br J Biomed Sci. 2015;72(3):93-101.\n\n"
+ "Effects of propofol and isoflurane on haemodynamics and the inflammatory response\n"
+ "in cardiopulmonary bypass surgery.\n\n"
+ "Sayed S, Idriss NK, Sayyedf HG, Ashry AA, Rafatt DM, Mohamed AO, Blann AD.\n\n"
+ "Cardiopulmonary bypass (CPB) causes reperfusion injury that when most severe is\n"
+ "clinically manifested as a systemic inflammatory response syndrome. The\n"
+ "anaesthetic propofol may have anti-inflammatory properties that may reduce such a\n"
+ "response. We hypothesised differing effects of propofol and isoflurane on\n"
+ "inflammatory markers in patients having CBR Forty patients undergoing elective\n"
+ "CPB were randomised to receive either propofol or isoflurane for maintenance of\n"
+ "anaesthesia. CRP, IL-6, IL-8, HIF-1α (ELISA), CD11 and CD18 expression (flow\n"
+ "cytometry), and haemoxygenase (HO-1) promoter polymorphisms (PCR/electrophoresis)\n"
+ "were measured before anaesthetic induction, 4 hours post-CPB, and 24 hours later.\n"
+ "There were no differences in the 4 hours changes in CRP, IL-6, IL-8 or CD18\n"
+ "between the two groups, but those in the propofol group had higher HIF-1α (P =\n"
+ "0.016) and lower CD11 expression (P = 0.026). After 24 hours, compared to the\n"
+ "isoflurane group, the propofol group had significantly lower levels of CRP (P <\n"
+ "0.001), IL-6 (P < 0.001) and IL-8 (P < 0.001), with higher levels CD11 (P =\n"
+ "0.009) and CD18 (P = 0.002) expression. After 24 hours, patients on propofol had \n"
+ "increased expression of shorter HO-1 GT(n) repeats than patients on isoflurane (P\n"
+ "= 0.001). Use of propofol in CPB is associated with a less adverse inflammatory\n"
+ "profile than is isofluorane, and an increased up-regulation of HO-1. This\n"
+ "supports the hypothesis that propofol has anti-inflammatory activity.\n\n"
+ "PMID: 26510263 [PubMed - indexed for MEDLINE]";
final Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS);
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