On Jul 21, 6:06 pm, shawnhco...@gmail.com (Shawn H Corey) wrote: > On 11-07-21 08:54 PM, Rob Dixon wrote: > ... > I think part of the confusion is also in what does $ match? According > to perlre, under "Regular Expressions", > > $ Match the end of the line (or before newline at the end) > > That means it can match the end of the string or a newline at the end of > the string. > > Try this and see what it prints: > > #!/usr/bin/env perl > > use strict; > use warnings; > > while( <> ){ > print if /(\w+)$/} > > __END__ >
Just entering a 'return' which will put a newline in $_ won't print if the target regex is /(\w+)+$/. Only [a-zA-Z_0-9] --or potentially more with certain locale settings-- will. But not a newline in any case. Even /(.+)$/ won't match a single newline at the end unless the regex '/s' modifier is used: perl -E "$_ = qq{\n}; say qq{matched\n} if /(.)$/" <-- no perl -E "$_ = qq{\n}; say qq{matched\n} if /(.)$/s" <---yes -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/