[EMAIL PROTECTED] wrote:
Gary Stainburn wrote:
On Monday 14 April 2008 16:35, Sharan Basappa wrote:
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
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
Nobody said it didn't. Gary just tried to explain why the things that
were captured may have differed from the OP's expectations. You may want
to read the FAQ entry
perldoc -q greedy
And, of course,
perldoc perlre
into $str?
Nothing is putted into $str. $str is the string on which the regex is
applied.
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
Nobody said it didn't.
and put it into $str?
Nothing is putted into $str. $str is the string on which the regex is
applied.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/