GNU sed中的前瞻性正则表达式有什么问题? [英] What's wrong with my lookahead regex in GNU sed?
本文介绍了GNU sed中的前瞻性正则表达式有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我正在做的事(简化示例):
This is what I'm doing (simplified example):
gsed -i -E 's/^(?!foo)(.*)$/bar\1/' file.txt
我试图将bar
放在不是以foo
开头的每一行的前面.这是错误:
I'm trying to put bar
in front of every line that doesn't start with foo
. This is the error:
gsed: -e expression #1, char 22: Invalid preceding regular expression
怎么了?
推荐答案
据我所知,sed
既没有前瞻性也没有前瞻性.切换到具有类似语法的更强大的语言,例如perl
.
As far as I know sed
has not neither look-ahead nor look-behind. Switch to a more powerful language with similar syntax, like perl
.
这篇关于GNU sed中的前瞻性正则表达式有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文