Does this do what you want?
use strict; use warnings; my $content = do { local $/; <DATA> }; while ($content =~ m/^(CAL.+?\((\w+)\).*?})/msg){ print "1= $1\n\n"; print "2= $2\n\n"; } __DATA__ CALCON(test1) { TYPE(U8) FEATURE(DCOM) NAM(stmin) LABEL(Min seperation time between CFs) MIN(0) MAX(127) UNITS(ms) } CALCON(test2) { TYPE(U16) FEATURE(DCOM) NAM(dcomc_sestmr_timeout) LABEL(DCOM Session Timer Timeout) MIN(0) MAX(65535) UNITS(ms) } __END__ 1= CALCON(test1) { TYPE(U8) FEATURE(DCOM) NAM(stmin) LABEL(Min seperation time between CFs) MIN(0) MAX(127) UNITS(ms) } 2= test1 1= CALCON(test2) { TYPE(U16) FEATURE(DCOM) NAM(dcomc_sestmr_timeout) LABEL(DCOM Session Timer Timeout) MIN(0) MAX(65535) UNITS(ms) } 2= test2
Note the two ? modifiers in the regex (after + and *) that prevent greedy matching. Without them, your matches would be longer than you want.
the lowliest monk
In reply to Re: nested reg ex over multiple lines
by tlm
in thread nested reg ex over multiple lines
by eg8rds
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |