正则表达式 – 由sed给出的前面正则表达式无效
发布时间:2020-12-14 06:26:17 所属栏目:百科 来源:网络整理
导读:我一直在处理sed脚本文件,当我运行它时,我遇到了“Invalid Preceding regular expression”错误.以下是整个文件. 我已经在这个网站上做了很多搜索,无论是在这个网站还是在哪里.这里提出的许多问题导致需要扩展正则表达式,而不正确地转义.我已将此定义为扩展
我一直在处理sed脚本文件,当我运行它时,我遇到了“Invalid Preceding regular expression”错误.以下是整个文件.
我已经在这个网站上做了很多搜索,无论是在这个网站还是在哪里.这里提出的许多问题导致需要扩展正则表达式,而不正确地转义.我已将此定义为扩展表达式,因为它是电子邮件替换所需的. #!/bin/sed -rf #/find_this thing/{ #s/ search_for_this/ replace_with_this/ #s/ search_for_this_other_thing/ replace_with_this_other_thing/ #} #Search and replace #ServerAdmin (with preceding no space) email addresses using a regular expression that has the .com .net and so on domain endings as option so it will find root@localhost and replace it in line with admin's email address. ServerAdmin/ { s/b[A-Za-z0-9._%-]+@(?:[a-zA-Z0-9-]+.)+(.[A-Za-z]]{2,4})?b/email@example.com/ } #Enable user's Public HTML directories /UserDir/ { s/disable$/enable/ s/^#User/User/ } #Replace the only #ServerName (with preceding no space) followed space and text with Our server ip /#ServerName */ c ServerName server.ip.address.here/ 我将它从termal调用为./config-apache.sed /etc/httpd/conf/httpd.conf并将其返回. /bin/sed: file ./apache-install.sed line 12: Invalid preceding regular expression 在vim第12行的内部我被识别为#Enable用户的公共HTML目录之上的单个}
似乎GNU sed不喜欢PCRE非捕获表示法:
...(?:...)... 尝试: s/b[A-Za-z0-9._%-]+@([a-zA-Z0-9-]+.)+(.[A-Za-z]]{2,4})?b/email@example.com/ GNU sed似乎没问题.但是,你还有一些工作要做.给定下面的第一行作为输入,输出是第二行: abc def@ghi.jk aaa abc email@example.comjk aaa 给出这个结果有两个问题: >]]应该是单一的]. 这样做的工作: s/b[A-Za-z0-9._%-]+@([a-zA-Z0-9-]+.)+([A-Za-z]{2,4})?b/email@example.com/ abc def@ghi.jk aaa abc email@example.com aaa (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |