Regex search/replace while preserving groups

For reference, I’m noting down here how to do a search and replace using regex when the text being replaced/removed is surrounding some text I want to keep. This came up in code with lots of occurrences of higher order functions: