Parsing HTML
You should not use regular expressions to parse HTML.
Regular expressions are insufficiently sophisticated for capturing the various patterns of constructs employed by HTML. HTML is not a regular language, and therefore cannot be accurately parsed by regular expressions.
Suppose you want to parse some simple HTML shown below. Notice that the parsing routine below will break if the HTML switches from using double quotes to single quotes, which remains valid HTML in the eyes of a web browser.
Loading TypeScript...
There are countless libraries out there for parsing HTML. If you are using Node.js, you can use node-html-parser to efficiently generate a virtual DOM tree.