From fcf045750d9836145305000be32b502fa043b6c0 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Tue, 4 Sep 2018 17:55:11 +0200 Subject: [PATCH] Updated sample code output A bit of cleanup and commentary, also switched to using $input as the variable name, since this is what the regex tester uses internally. --- web/regex_tester.html | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/web/regex_tester.html b/web/regex_tester.html index 1bb6382..e5cd48b 100644 --- a/web/regex_tester.html +++ b/web/regex_tester.html @@ -397,30 +397,34 @@ sub actual_update { __SAMPLES__ ); - for my $sample (@samples) { - print "### Sample: \"$sample\"\n"; + for my $input (@samples) { + print '### Sample: "', $input, '"', "\n"; ENDCODE $sampcode =~ s{__SAMPLES__}{ join ",\n", map {" ".pp($_)} @samps }e; $sampcode .= $precode=~s/^/ /mgr if length $precode; if ($flags=~/g/) { $sampcode .= <<~'ENDCODE'; - while ( $sample =~ __REGEX__ ) { - print "Match! \"$&\"\n"; - # can use $1, $2, etc. here + while ( $input =~ __REGEX__ ) { + __BODY__ } ENDCODE } else { $sampcode .= <<~'ENDCODE'; - if ( $sample =~ __REGEX__ ) { - print "Match! \"$&\"\n"; - # can use $1, $2, etc. here + if ( $input =~ __REGEX__ ) { + __BODY__ } else { print "No match!\n"; } ENDCODE } + chomp( my $matchbody = <<~'ENDCODE' ); + print 'Match! "', $&, '"', "\n"; + # (Note: $& has performance penalty on Perl <5.20) + # You can use $1, $2, etc. here. + ENDCODE + $sampcode =~ s/__BODY__/$matchbody/; my $re = $regex_str; if ( $re=~/\n/ && $flags=~/x/ ) { $re =~ s/^/ /mg;