[英]Regex: How to insert text before the first line and after the last line of file
[英]How to insert a line break in perl after the first + that appears in text
例如
*aabc aacb aavg +gf avb avb abf
应该
*aabc aacb aavg
+gf avb avb abf
谢谢
使用替代:
my $text = '*aabc aacb aavg +gf avb avb abf';
$text =~ s/\+/\n+/;
print $text;
+
必须反斜线以失去其特殊含义, \\n
是换行符。
my $str = "*aabc aacb aavg +gf avb avb abf";
$str =~ s/\+/\n\+/;
print $str;
> echo "abcd +gkj +bcd" | perl -pe 's/\+/\n\+/'
abcd
+gkj +bcd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.