开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜