Assuming the document is well-formed enough to parse the correct tree of DOM objects, you can iterate through the entire structure without using an external library. Depending on the structure, you may need to examine each node to find all matches, and this may be slow. If you have access to any type of identifier, you can reduce the search scope and improve performance.
The key property you'll need is the childNodes collection on each DOM node. Starting with BODY (or another container), you can rewrite all child nodes.
This site is pretty simple, but shows dependency-free methods for accessing DOM elements. See the section βTools for navigating to a specific itemβ.
I noticed that you mentioned regular expressions as a means of finding elements. Regular expressions are part of the JavaScript language and can be very useful when evaluating the text content of a single node (for example, partial matches, pattern matches, case insensitive, etc.). Regular expressions are part of the JavaScript language and have been like this for more than a decade.
source share