+1, structural regular expressions are a joy to use.
https://doc.cat-v.org/bell_labs/sam_lang_tutorial/sam_tut.pd...
Also interesting, with other derivates of ed -- LineEditorFamily in the TextEditors Wiki: https://texteditors.org/cgi-bin/wiki.pl?LineEditorFamily
There is a Go port of Sam, which is easy to install:
go install 9fans.net/go/cmd/sam@latest
http://sam.cat-v.org/