nutshell has asked for the wisdom of the Perl Monks concerning the following question:

Using the regex "my (@parms) = $source =~ m/\s+(?:new\s+)?My::Pkg(?:->new\s*?)?\((.*?)\);/gcs;" to process the below text, the data in @parms gets truncated when, in the text, a ");" is found (I marked the spot).

How can I make it so it'll keep slurping into @parms until it reaches the very last ");" in the text?

The text:

My::Pkg->new( 'key' => 'Fun', 'this' => ');' # <- here!! ); 1;

Please help!
--nutshell

Replies are listed 'Best First'.
Re: regex problem
by Paladin (Vicar) on Dec 23, 2002 at 05:47 UTC
    The (.*?) in your regex uses minimal matching so it stops at the first ); it finds. Use (.*) if you want it to capture until the last );.
Re: regex problem
by pg (Canon) on Dec 23, 2002 at 05:55 UTC
    You may base your regexp on this: (This one matches ), but not those following '. )
    $s = "(abcd')'1234)"; $s =~ m/(\(.*?(?<!\')\))/; print $1;
    Be careful, I took two assumptions, which fit your sample data:
    1. there is no \'(backslash quot)
    2. if you have ) in quots, it always comes right after the '