我在 GNU sed 中的前瞻正则表达式有什么问题? [英] What's wrong with my lookahead regex in GNU sed?

查看:18
本文介绍了我在 GNU sed 中的前瞻正则表达式有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我正在做的(简化示例):

This is what I'm doing (simplified example):

gsed -i -E 's/^(?!foo)(.*)$/bar1/' 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆