Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何使用perl正则表达式删除起始空格?_Regex_Perl - Fatal编程技术网

Regex 如何使用perl正则表达式删除起始空格?

Regex 如何使用perl正则表达式删除起始空格?,regex,perl,Regex,Perl,在perl中,如何表示空格? 如何使用perl正则表达式删除起始空格 $temp = " Hello world"; #print $temp; $temp =~ s/^\s+//; print $temp; 将显示: hello, world! 104 104是h的ASCII字符代码,证明该字符串没有前导空格 将显示: hello, world! 104 104是h的ASCII字符代码,证明字符串没有前导空格。这将搜索字符串开头(^)的重复空格(\s+),并用零替换(即此处分隔符之间

在perl中,如何表示空格? 如何使用perl正则表达式删除起始空格

$temp = "   Hello world";
#print $temp;
$temp =~ s/^\s+//;
print $temp;
将显示:

hello, world!
104
104是
h
的ASCII字符代码,证明该字符串没有前导空格

将显示:

hello, world!
104

104是
h
的ASCII字符代码,证明字符串没有前导空格。

这将搜索字符串开头(
^
)的重复空格(
\s+
),并用零替换(即此处分隔符之间的内容:
/
):


这将搜索字符串(
^
)开头的重复空格(
\s+
),并用零替换(即此处分隔符之间的内容:
/
):

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