regex - Bash 正则表达式替换两个不同字符串之间的所有内容

标签 regex bash

我想替换 #Start wp conf#End wp conf 之间的所有内容:

#Start wp conf
<Directory "/home/user/public_html/">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
</Directory>
#End wp conf

我尝试了sed -i -e“s/#Start wp conf.*#End wp conf//g”/root/test-conf但它没有替换任何内容。

我还尝试了sed -i -e "s/\(#Start wp conf\).*\(#End wp conf\)//g"/root/test-conf

最佳答案

使用 sed 你可以这样做:

sed '/#Start wp conf/,/#End wp conf/d' file

关于regex - Bash 正则表达式替换两个不同字符串之间的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51426129/

相关文章:

bash - BASH 变量名称中可以接受哪些 Unicode 符号?

arrays - 我如何在 ruby​​ 中用数组索引替换和数组元素?

javascript - 正则表达式在单词之间只允许一个空格

c# - 正则表达式数据注释不允许开始/结束空格(类似于修剪)

regex - 已解决 : Which RegexExtract parameters to extract number with different length & format

bash - 如果文件名在 Bash 中有前缀,则在句点之前去除字符

linux - 在 bash 脚本中连接两条指令

regex - 如何使用 -Filter (使用正则表达式)?

android - 在 android 中重命名脚本(无根)

python - 如何使用 "at"unix 命令直接从终端调度 python 脚本?