On Sat, 2006-01-07 at 01:29 +0200, Filip Jursik wrote: > Well, I thought, that when I write: > 1) /A(.*)B/, $1 will hold the longest string enclosed by A and B > 2) /A(.*?)B/, $1 will hold the shortest string enclosed by A and B > > Does it work like this or the "?" after the ".*" has a different meaning than > changing the match from the longest to the shortest possible one?
Not exactly. For: /A(.*?)B/ It will match the first A, then the shortest string to a B. For: /A(.*)B/ It will match the first A, then the longest string to B. #!/usr/bin/perl use strict; use warnings; chomp( my @strings = <DATA> ); print "/A(.*)B\n"; for ( @strings ){ /A(.*)B/; printf "%-30s %s\n", "'$_'", "'$1'"; } print "/A(.*?)B\n"; for ( @strings ){ /A(.*?)B/; printf "%-30s %s\n", "'$_'", "'$1'"; } __DATA__ A B A A B A B B A A B B A B B B B B B B B -- __END__ Just my 0.00000002 million dollars worth, --- Shawn "For the things we have to learn before we can do them, we learn by doing them." Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>