【发布时间】:2019-04-07 15:49:11
【问题描述】:
所以我尝试像这样替换行首的空格。
原文:
this
is
\tsome
text
我想要什么:
+this
+is
+
+some
+ text
我尝试使用这个正则表达式来做到这一点:
echo -e 'this\n is\n\n\tsome\n text' |
perl -wpe 's/^\s?(.*)/+$1/'
但这就是结果:
+this
+is
++some
+ text
所以我没有正确处理没有文本的行。或者更确切地说,我不明白它为什么会这样。
知道为什么吗?
谢谢!
【问题讨论】:
-
也许你可以用
\h代替\s(见stackoverflow.com/questions/3469080/…)。 -
啊,是的,就是这么简单,谢谢!