Text Replacing

Hi, I have no idea where to start on this one, or even if it is possible using applescript.

I have a text file, with YAML formatting (using schema 3), set out like this

The spaces in front of the “bar:” etc are NOT tabs, they are 4 spaces, this is a necessary part of YAML.

My Question
Is it possible for a script to remove the entirety of the tree foo1, whist leaving foo2 and foo3, where I would request that the script search for “Me” (ignoring case)