I’m sorry but my regex expertise is pretty weak so I cannot help OP with that.
With a Python script one could use two dumber regexes (match and replace within match for tags section), but setting up Python is a bit of a pain.
Maybe some way with a Dataview + Templater method could also work within Obsidian but I doubt if anyone will write the script (I can’t).
The above workaround with linting first can work. I have recommended the plugin many times before.
Notepad++ tutorials can be found on the net, even in several StackOverFlow answers as well, or here, although that was for a different use case.
Alternatively, OP can put up a question for this use case on StackOverFlow. I have had good people help me out before there when I knew nothing about stuff like this.