import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<script>.*(adsConfig).*<\\/script>";
final String string = "<script>\n"
+ " var middleCount = 0;\n"
+ " var adsConfig = {\n\n\n\n\n\n"
+ " nonLinear: {\n"
+ " url: \"https://8245.digital/vpaid/?id=7875&type=nonlinear&dcc=1\",\n"
+ " total: 0 ,\n"
+ " offset: 10 * 60,\n"
+ " label: { name: 'label', val: 'overlay', counter: true }\n"
+ " },\n"
+ " \n"
+ " pre: {\n"
+ " maxImpressions: 2 ,\n"
+ " urls: [\"https://8245.digital/vpaid/?id=5241&label=preroll&dcc=1&maximp=2&synconly=1\"]\n\n"
+ " },\n"
+ " \n"
+ " middle: {\n"
+ " pop: true,\n"
+ " maxTotalImp: 0 ,\n"
+ " maxImpressions: 1,\n"
+ " urls: [\"https://8245.digital/vpaid/?id=21515&synconly=1&maximp=1&dcc=1&mid=6\",\"https://8245.digital/vpaid/?id=5242&synconly=1&maximp=1&dcc=1&mid=6\"]\n"
+ ",\n"
+ " getUrls: function () {\n"
+ " var u = middleCount && adsConfig.middle.urls\n"
+ " ? adsConfig.middle.urls.slice(1)\n"
+ " : adsConfig.middle.urls;\n"
+ " middleCount++;\n"
+ " return u;\n"
+ " },\n"
+ " \n"
+ " label: { name: 'label', val: 'middleroll', counter: true }\n"
+ " },\n"
+ " \n"
+ " confirmTimeout: 60 * 1000,\n"
+ " confirmOn: ['localhost', 'zombie-film.net'],\n"
+ " vast: {timeouts: {loading: 20000, starting: 20000, global: 120000}},\n"
+ " volume: 0.3,\n"
+ " tv: true,\n"
+ " suppressOnFakeFullScreen: true\n"
+ " };\n"
+ " </script>";
final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL | Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
if (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