I get a string in the form <red> Hello </red> World - where red means a red string, but how do such parsers work in general, I need a simple example please))...
You can use DOMParser
Example:
const parser = new DOMParser();
const htmlString = "<red> Hello </red> World";
const doc1 = parser.parseFromString(htmlString, "text/html");
// HTMLDocument
console.log(doc1.body.firstChild.textContent);
// Now you can make necessary edits with normal JS functions: .trim() etc.