import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^file *\"?([^\" ]*)\"[\\s\\S]*?((?:\\{[\\s\\S]*?)*?\\}[\\s\\S]\\})";
final String string = "#############################################################################\n"
+ "# DB substitution file generated by http://github.com/epics-containers/ibek #\n"
+ "#############################################################################\n\n"
+ "file \"$(IOCSTATS)/db/iocAdminSoft.db\" {\n"
+ "pattern \n"
+ " { \"IOC\" }\n"
+ " { \"BL01T-EA-TST-02\" }\n"
+ "}\n\n"
+ "file \"$(IOCSTATS)/db/iocAdminScanMon.db\" {\n"
+ "pattern \n"
+ " { \"IOC\" }\n"
+ " { \"BL01T-EA-TST-02\" }\n"
+ "}\n\n"
+ "file \"$(ADSIMDETECTOR)/db/simDetector.template\" {\n"
+ "pattern \n"
+ " { \"P\", \"R\", \"PORT\", \"TIMEOUT\", \"ADDR\" }\n"
+ " { \"BL01T-EA-TST-02\", \":DET:\", \"DET.DET\", \"1\", \"0\" }\n"
+ "}\n\n"
+ "file \"$(ADCORE)/db/NDPva.template\" {\n"
+ "pattern \n"
+ " { \"NDARRAY_PORT\", \"ADDR\", \"SCANRATE\", \"NDARRAY_ADDR\", \"ENABLED\", \"P\", \"R\", \"TIMEOUT\", \"PORT\" }\n"
+ " { \"DET.DET\", \"0\", \"I/O Intr\", \"0\", \"0\", \"BL01T-EA-TST-02\", \":PVA:\", \"1\", \"DET.PVA\" }\n"
+ "}\n\n"
+ "file \"$(ADCORE)/db/NDStdArrays.template\" {\n"
+ "pattern \n"
+ " { \"NDARRAY_PORT\", \"FTVL\", \"ADDR\", \"SCANRATE\", \"NELEMENTS\", \"NDARRAY_ADDR\", \"ENABLED\", \"P\", \"R\", \"TIMEOUT\", \"TYPE\", \"PORT\" }\n"
+ " { \"DET.DET\", \"CHAR\", \"0\", \"I/O Intr\", \"1048576\", \"0\", \"0\", \"BL01T-EA-TST-02\", \":ARR:\", \"1\", \"Int8\", \"DET.ARR\" }\n"
+ "}\n\n"
+ "file \"simDetector.pvi.template\" {\n"
+ "pattern \n"
+ " { \"P\", \"R\" }\n"
+ " { \"BL01T-EA-TST-02\", \":DET:\" }\n"
+ "}\n\n"
+ "file \"NDPluginPva.pvi.template\" {\n"
+ "pattern \n"
+ " { \"P\", \"R\" }\n"
+ " { \"BL01T-EA-TST-02\", \":PVA:\" }\n"
+ "}\n\n"
+ "file \"NDPluginStdArrays.pvi.template\" {\n"
+ "pattern \n"
+ " { \"P\", \"R\" }\n"
+ " { \"BL01T-EA-TST-02\", \":ARR:\" }\n"
+ "}\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