gpt4 book ai didi

regex - sed -E 和 sed -e 有什么区别

转载 作者:IT王子 更新时间:2023-10-29 00:20:20 25 4
gpt4 key购买 nike

我正在处理一些旧代码,我发现我曾经使用过

sed -E 's/findText/replaceWith/g' #findText would contain a regex

但我现在试试

sed -e 's/findText/replaceWith/g'

它似乎在做同样的事情,是吗?我有点记得我这样做是有原因的,但我不记得了,做“man sed”并没有帮助,因为他们没有任何关于 -E only -e 的东西,这没有多大意义。

-e, --expression=script
Append the editing commands in script to the end of
the editing command script. script may contain more
than one newline separated command.

我以为 -e 意味着它会与正则表达式匹配......

GNU sed version 4.2.1

最佳答案

从源代码来看,-E 是与 BSD sed 兼容的未记录选项。

/* Undocumented, for compatibility with BSD sed.  */
case 'E':
case 'r':
if (extended_regexp_flags)
usage(4);
extended_regexp_flags = REG_EXTENDED;
break;

来自manual , BSD sed中的-E用于支持扩展的正则表达式。

关于regex - sed -E 和 sed -e 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3139126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com