Greedy and non-greedy quantifiers : Greedy « Regular Expression « Perl






Greedy and non-greedy quantifiers

    
#!usr/bin/perl


use strict;
use warnings;

my $string1 = "there  here  There  here there Here";
my $string2 = $string1;

print "$string1\n";
$string1 =~ s/N.*here\.//;
print "$string1\n";
print "$string2\n";
$string2 =~ s/N.*?here\.//;
print "$string2\n\n";

   
    
    
    
  








Related examples in the same category

1.Greedy Matches
2.Greedy searches
3.The Greedy Metacharacters
4.The greedy quantifier
5.Turning Off Greediness
6.A greedy quantifier
7.Shortcut Expansion Description
8.Shortcuts for Regular Expressions
9.Shortest possible match