use strict;
my $str = '<script>
var middleCount = 0;
var adsConfig = {
nonLinear: {
url: "https://8245.digital/vpaid/?id=7875&type=nonlinear&dcc=1",
total: 0 ,
offset: 10 * 60,
label: { name: \'label\', val: \'overlay\', counter: true }
},
pre: {
maxImpressions: 2 ,
urls: ["https://8245.digital/vpaid/?id=5241&label=preroll&dcc=1&maximp=2&synconly=1"]
},
middle: {
pop: true,
maxTotalImp: 0 ,
maxImpressions: 1,
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"]
,
getUrls: function () {
var u = middleCount && adsConfig.middle.urls
? adsConfig.middle.urls.slice(1)
: adsConfig.middle.urls;
middleCount++;
return u;
},
label: { name: \'label\', val: \'middleroll\', counter: true }
},
confirmTimeout: 60 * 1000,
confirmOn: [\'localhost\', \'zombie-film.net\'],
vast: {timeouts: {loading: 20000, starting: 20000, global: 120000}},
volume: 0.3,
tv: true,
suppressOnFakeFullScreen: true
};
</script>';
my $regex = qr/<script>.*(adsConfig).*<\/script>/smp;
if ( $str =~ /$regex/ ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
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 Perl, please visit: http://perldoc.perl.org/perlre.html