Using Regex to parse and manipulate HTML is a recipe for disaster. There are too many edge cases you have to account for.
If you really want to "optimize" the HTML, you may end up having to parse HTML into some kind of AST and work from there. But this is probably more complex than the editor itself you want to build.
But parsing html with regex is fun...
Not as much as having dinner at home. ;)
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.