正则表达式以任意顺序删除特定单词

use*_*919 1 regex perl words substitution optional

我要替换(删除)特定的可选单词(AAA,BBB,CCC),这些单词在特定单词(ALWAYS_THERE)前后紧随其后

this is important AAA BBB ALWAYS_THERE CCC
this is important BBB AAA ALWAYS_THERE CCC
this is important AAA CCC ALWAYS_THERE BBB
this is important BBB ALWAYS_THERE CCC AAA
this is important BBB this also ALWAYS_THERE CCC AAA
Run Code Online (Sandbox Code Playgroud)

至

this is important
this is important
this is important
this is important
this is important BBB this also
Run Code Online (Sandbox Code Playgroud)

如何在perl(或UNIX上的任何其他可用程序)中完成此操作?

Tim*_*rce 5

尝试这个:

s/\b(AAA\s+|BBB\s+|CCC\s+)*ALWAYS_THERE(\s+AAA|\s+BBB|\s+CCC)*\b//g;
Run Code Online (Sandbox Code Playgroud)

[编辑以\b按@ikegami 添加开头和结尾]