后视在 sed 中工作吗? [英] Does lookbehind work in sed?
本文介绍了后视在 sed 中工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 grep
创建了一个测试,但它在 sed
中不起作用.
I created a test using grep
but it does not work in sed
.
grep -P '(?<=foo)bar' file.txt
通过返回 bar
可以正常工作.
This works correctly by returning bar
.
sed 's/(?<=foo)bar/test/g' file.txt
我期待 footest
作为输出,但它不起作用.
I was expecting footest
as output, but it did not work.
推荐答案
GNU sed 不支持环视断言.您可以使用更强大的语言,例如 Perl,也可以尝试使用支持的 ssed
Perl 风格的正则表达式.
GNU sed does not have support for lookaround assertions. You could use a more powerful language such as Perl or possibly experiment with ssed
which supports Perl-style regular expressions.
perl -pe 's/(?<=foo)bar/test/g' file.txt
这篇关于后视在 sed 中工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文