Next Regular Expression Mastery 28

Why the Greedy Ones are the Defaults

        # $s contains a line of code:
        $s = '($label =~ tr/.//) < 3; # do not attach these';
        # Let's strip out comments
        $s =~ s/#.*//;
        '($label =~ tr/.//) < 3; '
        '($label =~ tr/.//) < 3;  do not attach these';
        # In the parallel universe where * is nongreedy
        $s =~ s/#.*$//;         


Next Copyright © 2002 M. J. Dominus