Is there a Perl-compatible regular expression to trim whitespace from both sides of a string?

前端 未结 13 941
醉话见心
醉话见心 2021-02-08 07:45

Is there a way to do this in one line?

$x =~ s/^\\s+//;
$x =~ s/\\s+$//;

In other words, remove all leading and trailing whitespace from a stri

相关标签:
13条回答
  • 2021-02-08 08:42
    $var1 =~ s/(^\s*)(.*?)(\s*$)+/$2/;
    
    0 讨论(0)
提交回复
热议问题