Raw Input
Word: cat!! An indicator is neither a cat nor a catalog, not related to a cat.
Desired Output
Word: !! An indicator is neither a  nor a catalog, not related to a .
Description
  • If a line has a word followed by `!!', delete all instances of that word.
  • The following script only processes the word preceding the first `!!'.
  • In the example, the word to be deleted is `cat'. `catalog', `indicator' should be kept intact.
Script and Comments
Script1
[ 1] :loop
[ 2] s/\b((\w+)!!.*)\b\2\b/\1/
[ 3] t loop
[ 4] s/\b(\w+)!!/!!/
Comments
  1. Terminology related to `word's:
    • A word consists of only word characters where a word character can be a letter, a digit, or an underscore.
    • \w means a character class matches any word character.
    • \b means a word boundary where one side of of it is a word character while the other side is not.
  2. Steps [1] thru [3] constitute a loop which iterates until there are no instances of the word in question.
  3. In Step [2], the second pair of parentheses is used to capture the word preceding `!!'.