PCRE 正则表达式到 sed 正则表达式 [英] PCRE regex to sed regex
本文介绍了PCRE 正则表达式到 sed 正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
首先很抱歉我的英语不好.我是德国人.
First of all sorry for my bad english. I'm a german guy.
下面给出的代码在 PHP 中运行良好:
The code given below is working fine in PHP:
$string = preg_replace('/href="(.*?)(\.|\,)"/i','href="$1"',$string);
现在 sed
也需要同样的东西.我觉得应该是:
Now T need the same for sed
. I thought it should be:
sed 's/href="(.*?)(\.|\,)"/href="{$\1}"/g' test.htm
但这给了我这个错误:
sed:-e 表达式 #1,字符 36:`s' 命令的无效引用 \1右图
sed: -e expression #1, char 36: invalid reference \1 on `s' command's RHS
推荐答案
sed -e 's|href=\"\(.[^"][^>]*\)\([.,]\)\">|href="\1">|g' file
这篇关于PCRE 正则表达式到 sed 正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文