Perl code
use strict;
use warnings;
my $str=" \n aaa bbb\n ";
$str=~s/^\s+|\s+$//g;
print($str);
^D
aaa bbb
use strict;
use warnings;
my $str=" \n aaa bbb\n ";
$str=~s/^\s+|\s+$//g;
print($str);
^D
aaa bbb
本文展示了Perl中使用正则表达式处理字符串的方法,包括去除字符串首尾空格的例子。

被折叠的 条评论
为什么被折叠?