| ||||||
| 5/17 |
| 2004/7/27 [Computer/SW/Languages/Perl] UID:32492 Activity:high |
7/26 In Perl, s/.*/foo/g will match twice and produce foofoo but
s/.+/foo/g only once and produces foo. Why?
\_ Maybe because .* means zero or more, so it matches the zero too?
\_ .* first matches starting from the beginning of the string until
end, consuming all the characters. Then it tries to match the
empty string at the end of the string, and succeeds since it will
match 0 characters. .+ does not match 0 characters, so it does not
match the empty string at the end. |