rkabhi has asked for the wisdom of the Perl Monks concerning the following question:
I am new to named groups in Perl regex. I am using perl 5.16.0
Below code works as expected:
$_ = "This is a teeeext for testting"; /(?<char>.*)/ and print "'$+{char}' is matched pattern\n"; # This prints 'This is a teeeext for testting' is matched pattern
Replacing '.' with 'e' in regular expression above leaves matched pattern as blank at the beginning:
$_ = "This is a teeeext for testting"; /(?<char>e*)/ and print "'$+{char}' is matched pattern\n"; # This prints '' is matched pattern
I was expecting output of above code to be => 'eeee' is matched pattern Please enlighten why the output is different? Is the * modifier becoming non-greedy or is there any other way to understand this?
|
|---|