Perl Greedy Matching





How much does Perl return when there are more than one match?" For example, what would you expect Perl to print when you run the following?
$Test="NITWITS";
if($Test=~/(N.*T)/)
{print"True\n";}
else
{
print"False\n";}
print "$1/n";
The results is
True
NITWIT
You, can suppress Perl's greedy ways by following a quantifier with a question mark =~ When you do this, Perl matches the shortest possible string instead of the longest string. For example, note the small change to the previous program.
$test= 'NITWITS';
if($Test =~ /(N. *?T)/)
print "True\n";
else (print "False\n"; print ''$1\n".
Here Is the now output, True NIT
Domain Name Search
|