Only1KW has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to write a regex replace to be run on a line containing a newline and I want the newline character to not be replaced. It seems like \s is matching the newline character, and I have no idea why or how to prevent that. I'm not using '$' or '.' in my regex, so I am not using a 'm' or 's' modifier. Any ideas?
Example script:
#!/usr/bin/perl use strict; use warnings; my $line = "Hi\n"; print length($line) . "\n"; $line =~ s/Hi\s*//; print length($line) . "\n";
Output I get:
I'm running v5.18.2 if it matters.3 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: \s matches newline in regex? ([^\S\n])
by tye (Sage) on Jul 22, 2015 at 16:56 UTC | |
|
Re: \s matches newline in regex?
by toolic (Bishop) on Jul 22, 2015 at 16:32 UTC | |
by Only1KW (Sexton) on Jul 22, 2015 at 16:49 UTC | |
by Corion (Patriarch) on Jul 22, 2015 at 17:04 UTC | |
by GrandFather (Saint) on Jul 22, 2015 at 20:58 UTC | |
|
Re: \s matches newline in regex?
by stevieb (Canon) on Jul 22, 2015 at 16:41 UTC | |
by AnomalousMonk (Archbishop) on Jul 22, 2015 at 23:31 UTC | |
by stevieb (Canon) on Jul 22, 2015 at 23:38 UTC | |
|
Re: \s matches newline in regex?
by kroach (Pilgrim) on Jul 22, 2015 at 17:41 UTC |