Thanks Gary,
But some of us may wish to know why $str =~ m/tokena(.*)tokenb/ms; did not get all the things between tokena and tokenb into $str?

This is how my mind think:-
(1) The /s switch means to be able to match across newlines.
(2) .* means to match zero or more of anything.

Henceforth some of our minds will be thinking why the above expression did not match anything between tokena and tokenb and put it into $str?
Can somebody please explain?

Thanks

----- Original Message ----- From: "Gary Stainburn" <[EMAIL PROTECTED]>
To: <beginners@perl.org>
Sent: Monday, April 14, 2008 11:41 PM
Subject: Re: grabbing text between two tokens


On Monday 14 April 2008 16:35, Sharan Basappa wrote:
Hi,

I am trying to capture the text between two tokens. These tokens
always exist in pairs but can occur N times.
I somehow dont get what I want.

$str =~ m/tokena(.*)tokenb/ms;
print $1;

Try

$str =~ m/tokena(.*?)tokenb/ms;

The ? after the * stops it being greedy - i.e. it stops at the 1st tokenb and
not the last

Gary
--
Gary Stainburn


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


Reply via email to