nagalenoj has asked for the wisdom of the Perl Monks concerning the following question:
I have to take the first 2 columns out from a line(using regular expression). For that I have written a code like follows,
use strict; use warnings; $lines = 'B6y green $1$Byf3501d$dPtaW2vCbq63sdsw'; $lines =~ s/^(\S+\s\S+)/$1/; print "$lines";
But, its matching the whole line. why?
When I have changed the regex as follows, its working fine. How both differs. Why the first one doesn't work?
$lines =~ s/^(\S+\s\S+).*/$1/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How regex works here?
by lakshmananindia (Chaplain) on Apr 08, 2009 at 05:27 UTC | |
by nagalenoj (Friar) on Apr 08, 2009 at 05:38 UTC | |
by bart (Canon) on Apr 08, 2009 at 09:01 UTC | |
|
Re: How regex works here?
by codeacrobat (Chaplain) on Apr 08, 2009 at 06:36 UTC | |
|
Re: How regex works here?
by AnomalousMonk (Archbishop) on Apr 08, 2009 at 07:11 UTC |