TEST1 is supposed to match entries with BOTH EXT and INT curly delimiters update: so it SHOULD capture 2 matches in Dataline 1 but (per testing and hash contents) it is capturing only the first match in DataLine 1 -- SEE note 2. It correctly captures a single match in DataLine2
NOTE 1: regex in extended format & commented is update in the readmore (was referenced to ww's scratchpad)
NOTE 2: IF this is modified with an initial .* before the capture, the "{three 1 1 {...} {...}}" matches
#!C:/perl/bin -w use strict; use Data::Dumper::Simple; use vars qw ( $i $j $tmp $test @data @found $found %h ); $i = 1; # tracking counter - in full version does NOT necessarily +== $j $j = 0; # track datalines %h = (); while (<DATA>) { push @data,$_ ; } foreach $test(@data) { test1($test); } &hashprint; exit(); ################ subs ############# sub test1 { # first, get rid of previous array conents (needed i +n full vers) undef(@found); # Categorized Q&A book answer; "@found = ();" is an +alternate $j++; print "\n\t ***** STARTING dataline $j ****\n\n"; if ($test =~ /(\{{1}[a-z]{4,5}\s\d\s\d\s[^}]+?\}\s\{[^}]+?\}{2})/gx ) + # see NOTE1 { if ( $1 ) { $tmp = "\t\$j" . $j . "\$i". $i . ": " . $1 . "\n"; push @found, $tmp; &hashify; print "TEST1 regex, dataline $j found match(es)\n"; print "\t $1\n"; } else { print "\t TEST1 dataline $j, NO matches.\n"; } } $i++; return($i) } # end sub test1 # (more similar tests here in full version) ############## sub hashify { $h {'datalinej'.$j."_i".$i} {"j".$j."i" .$i} = "@found"; # get all @fo +und's elements into hash ??? $tmp = ''; return(); } # end hashify ########### sub hashprint { print "\n\t\t~~~~~~~~~~~~~~~~ Dumping hash (HoA)\n"; print Dumper (%h); print "\t\t~~~~~~~~~~~~~~~~ ending dump\n"; } # end sub hashprint and end subs __DATA__ DataLine1 {error 1 1 {^E 0-20-9:0-50-9:0-50-9.*$} {^E 0-20-9:0-50-9:0- +50-9.*$}} {three 1 1 {^.*35=A.*$|^.*35=5.*$} {^.*35=A.*$|^.*35=5.*$}} + {fixv 1 1 ^.*VFIXFxProxy.*Disconnected ^.*VFIXFxProxy.*Disconnected} DataLine2 error 1 1 {^E 0-20-9:0-50-9:0-50-9.*$} {^E 0-20-9:0-50-9:0-5 +0-9.*$} {three 1 1 {^.*35=A.*$|^.*35=5.*$} {^.*35=A.*$|^.*35=5.*$}} { +fixv 1 1 ^.*VFIXFxProxy.*Disconnected ^.*VFIXFxProxy.*Disconnected}
and, update per merlyn's note, the commented regex for TEST1 is:***** STARTING dataline 1 **** TEST1 regex, dataline 1 found match(es) {error 1 1 {^E 0-20-9:0-50-9:0-50-9.*$} {^E 0-20-9:0-50-9:0-5 +0-9.*$}} ***** STARTING dataline 2 **** TEST1 regex, dataline 2 found match(es) {three 1 1 {^.*35=A.*$|^.*35=5.*$} {^.*35=A.*$|^.*35=5.*$}} ~~~~~~~~~~~~~~~~ Dumping hash (HoA) %h = ( 'datalinej1_i1' => { 'j1i1' => ' $j1$i1: {error 1 1 {^E 0-20-9: +0-50-9:0-50-9.*$} {^E 0-20-9:0-50-9:0-50-9.*$}} ' }, 'datalinej2_i2' => { 'j2i2' => ' $j2$i2: {three 1 1 {^.*35=A.*$ +|^.*35=5.*$} {^.*35=A.*$|^.*35=5.*$}} ' } ); ~~~~~~~~~~~~~~~~ ending dump
$test =~ / ( # capture \{{1} # SINGLE open curlybrace [a-z]{4,5} # followed by 4 or 5 lowercase letters \s\d\s\d\s # fol by whitespace, digit, whitespace, digit, + space [^}]+? # fol by anything_not_a_closingcurly, one-or-m +ore_times-but-as_few_as_poss \}\s\{ # closingcurly fol by whitespace fol by opencu +rly (tween element 4 and element 5) [^}]+? # fol by anything_not_a_closingcurly, one-or-m +ore_times-but-as_few_as_poss \}{2} # closingcurly twice )/gx; # end capture, global, xtended syntax, end if_t +est
In reply to multiple matches in regex by ww
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |