regex – sed错误:“s’命令的RHS上的无效引用\ 1”
问题:
我运行几个替换命令作为maven的colorize脚本的核心。 其中一个sed
命令使用一个正则表达式,它可以在shell中找到,如下所述 。 可以在此处找到当前(不工作)的实现。
当我将该命令的一个变体包含到脚本中时,会出现不同的行为:
变式1:
$ sed -re "s/([a-zA-Z0-9./\\ :-]+)/\1/g"
适应脚本:
-re "s/WARNING: ([a-zA-Z0-9./\\ :-]+)/${warn}WARNING: \1${c_end}/g" \
错误: shell输出的信息与我输入$ sed
信息相同。 奇怪!?
变式2:
$ sed -e "s/\([a-zA-Z0-9./\\ :-]\+\)/\1/g"
适应脚本:
-e "s/WARNING: \([a-zA-Z0-9./\\ :-]\+\)/${warn}WARNING: \1${c_end}/g" \
错误:
sed:-e表达式#7,char 59:`s’命令的RHS上的引用\\ 1无效
I run several substitution commands as the core of a colorize script for maven .One of the sed
commands uses a regular expression which works find in the shell as discussed here .The current (not working) implementation can be found here .When I include one of the variants of the command into the script different behavior occurs:Variant 1:Adapted to the script:Error: The shell outputs the same information as if I would type $ sed
.Strange!?Variant 2:Adapted to the script:Error:sed: -e expression #7, char 59: invalid reference \\1 on `s’ command’s RHS