/s: 如果你的意思是删除输入中的空白行,可以考虑用“替换”:s//s+//g
/^$/ # 什么都没有的行,除了/n
/^/s+$/ # 只有space, tab, ... 的行
|$`<$&>$'|
|<>|是普通符号
$`, $&, $'是三个变量,将被匹配的字符串按匹配部分之前、匹配部分、匹配部分之后分割。
如果字符串以"/n"结尾,chomp去掉最后的"/n",返回1;如果字符串不以"/n"结尾,chomp直接返回0。
|
正向先行预测 (?=);反向先行预测 (?!) 例子: print "$1/n" if "abcdefg" =~ /(?=d)(....)/;
print "$1:$2/n" if "abcdefgh" =~ /(d)(...)/;
print "$1/n" if "abcdefg" =~ /(d)(...)/; Result as: defg
d:efg
d
===〉匹配符“//”中第二个()中“.”的个数代表匹配结果后要有几个字符