#!/usr/bin/perl
use strict;
use warnings;
my $re = qr{
(?&opengamediv) (?# opening div contating start of data )
id="(?<gameid>\d+)-game" (?# gameid --> id='12345-game' -> 12345 )
(?<content>.*?) (?# Skip a lot of content non-greedily )
(?&comment_open) (?# open comment contatining status )
=\s*(?<gamestate>\d+) (?# gamestatus=12344 -> 12344 )
(?&comment_close) (?# closing comment to make sure we get all digits )
(?# Rules )
(?(DEFINE)
(?<opengamediv><div\s* class="game"\s* )(?# This comes before our data )
(?<comment_open> <!--gamestatus\s* )(?# game status in a comment )
(?<comment_close> --> )(?# overkill )
)}xsim;
my @d = ();
my $s = <<'EOF';
<div class="game" id="12345-game"> hello world fooo bar
<!--gamestatus=1288-->
</div>
EOF
if ( $s =~ $re ) {
print "The Expression matched, resulting variables were discovered. : \n";
for my $key ( keys %+ ) {
printf "\t%s: %s\n", $key, $+{$key};
}
print "Used Expression: \n", $re, "\n";
}
else {
print "The Content Did not match the expression: \n", $re, "\n";
}