in reply to Re: nested reg ex over multiple lines
in thread nested reg ex over multiple lines

I have the entire file in one variable. I can get the result you have by leaving the ~m//mg rather than ~m//smg (single line mode.) My problem is that I want $1 to equal the entire element, i.e.
CALCON(test2) { TYPE(U16) FEATURE(DCOM) NAM(dcomc_sestmr_timeout) LABEL(DCOM Session Timer Timeout) MIN(0) MAX(65535) UNITS(ms) }
but $2 to equal "test2". perl seems to be greedy, and gets all the way to the "ms" in brackets if I add the /s to the match, i.e. it is greedy. Does this explain things better? Cheers.

Replies are listed 'Best First'.
Re^3: nested reg ex over multiple lines
by holli (Abbot) on Jun 20, 2005 at 13:49 UTC
    I have the entire file in one variable.
    Maybe you should have mentioned that. Anyway here's a working solution:
    use strict; use warnings; $_ = qq"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) }"; while ( /(CALCON\(\w+\)\n{\n[^}]+})/msg ) { print "****\n$1\n"; }
    Output:
    **** 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) }


    holli, /regexed monk/
Re^3: nested reg ex over multiple lines
by tphyahoo (Vicar) on Jun 20, 2005 at 14:18 UTC
    I came up with something that I think does what you want below using "inch along with negative lookahead" strategy.