如何在它们之后删除换行符和空格并用Perl中的空格字符替换它们?

时间:2011-04-13 19:05:15

标签: regex perl

如何使用Perl编写正则表达式模式:

**If there is a 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?

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

我不确定我是否理解你的问题。尝试:s{ \n\s+ }{ }gx