So since '?' will match the last character, group, or class 0 or 1 time the it 
matches the group of whatever happens to
be in '.*' up to any spaces that are attached to the '$'.

Is that correct?

Tony Heal


> -----Original Message-----
> From: Chas Owens [mailto:[EMAIL PROTECTED]
> Sent: Thursday, August 02, 2007 4:55 PM
> To: [EMAIL PROTECTED]
> Cc: beginners@perl.org
> Subject: Re: regex help
> 
> On 8/2/07, Tony Heal <[EMAIL PROTECTED]> wrote:
> snip
> > Why doesn't this work? I want to take any leading or trailing white spaces 
> > out.
> > If I remove the remark it works, but I
> > do not understand why it requires the second line
> >             $string =~ s/^(\s+)(.*)(\s+)$/$2/;
> snip
> 
> Because (.*) matches all but the one space needed by the second (\s+).
>  The . matches everything including the spaces.  You can fix this by
> saying
> 
> $string =~ s/^(\s+)(.*?)(\s+)$/$2/;
> 
> to make (.*) match the smallest pattern (non-greedy) instead of the
> largest (greedy).


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to