use strict;
my $str = '<html>
<head>~~</head>
<body>
<div>contents</div>
<script>
var value1 = 55;var value2= 27;
var value3 = \'T\';var value4 = "FIT#$%SIZE";
var value5 = \'{\\"P00000WJ000E\\":{\\"stock_price\\":\\"0.00\\",\\"use_stock\\":true,\\"use_soldout\\":\\"T\\",\\"is_display\\":\\"T\\",\\"is_selling\\":\\"T\\",\\"option_price\\":79000,\\"option_name\\":\\"FIT#$%SIZE\\",\\"option_value\\":\\"NOBLE-44\\",\\"stock_number\\":26,\\"option_value_orginal\\":[\\"NOBLE\\",\\"44\\"],\\"use_stock_original\\":\\"T\\",\\"use_soldout_original\\":\\"T\\",\\"use_soldout_today_delivery\\":\\"F\\",\\"is_auto_soldout\\":\\"F\\",\\"is_mandatory\\":\\"T\\",\\"option_id\\":\\"000E\\",\\"is_reserve_stat\\":\\"N\\",\\"item_image_file\\":null,\\"origin_option_added_price\\":\\"0.00\\"}}\';var value6 = \'1\';var value7 = \'string;must-catch\';
var value8 = 8;
var value9 = \'S\';
var value10 = \'T\';
</script>
</body>
</html>';
my $regex = qr/var\s(\w+)\s?\=\s?(\d+|\"[^\n"]*\"|\'[^\n']*\')\s?\;/mp;
if ( $str =~ /$regex/g ) {
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