我要替换(删除)特定的可选单词(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
至
this is important this is important this is important this is important this is important BBB this also
如何在perl(或UNIX上的任何其他可用程序)中完成此操作?
尝试这个:
s/\b(AAA\s+|BBB\s+|CCC\s+)*ALWAYS_THERE(\s+AAA|\s+BBB|\s+CCC)*\b//g;
[编辑以\b
按@ikegami 添加开头和结尾]