in reply to \s matches newline in regex?

You can also use a positive lookahead in the regex to avoid replacing the newline char.

$line =~ s/Hi\s*(?=\n)//;

Replies are listed 'Best First'.
Re^2: \s matches newline in regex?
by AnomalousMonk (Archbishop) on Jul 22, 2015 at 23:31 UTC

    If there were repeated, contiguous newlines, that would only avoid replacing the final newline.

    c:\@Work\Perl\monks>perl -wMstrict -le "my $line = qq{HeHi\n\n\nHo}; print qq{[$line]}; ;; $line =~ s/Hi\s*(?=\n)//; print qq{[$line]}; " [HeHi Ho] [He Ho]


    Give a man a fish:  <%-(-(-(-<

      Yes, I'm aware of that, but it would have been prudent for me to have pointed that out.

      Thanks AnomalousMonk.

      -stevieb