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.
I love education and technology! If you ever want help with anything, please message me here on Dev, on Twitter (@PullJosh), or by email (hello@joshuapullen.com)
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. ;)