开发者

How to remove newline character and white spaces after them and replacing them with just whitespace character in Perl?

开发者 https://www.devze.com 2023-02-24 05:21 出处:网络
How can I write a regex pattern with Perl that will work like that: **If there is a 开发者_Go百科new line**, after it, it will remove that new line character and all the whitespace characters after u

How can I write a regex pattern with Perl that will work like that:

**If there is a 开发者_Go百科new line**, after it, it will remove that new line character and all the whitespace characters after until it sees any character except for a white space character and will put just one whitespace character instead of them?


substitution operator

use warnings;
use strict;

my $s = "foo\n    bar goo\nber";
$s =~ s/\n\s*/ /g;
print "$s\n";

__END__

foo bar goo ber


I am not sure if I understand your question well. Try: s{ \n\s+ }{ }gx

0

精彩评论

暂无评论...
验证码 换一张
取 消