I want to know what might be the best way to get the title, keywords and content visible to the user from responseText using fetch api ( Is there a way to not send cookies when creating XMLHttpRequest on the same origin? )
I am currently using regular expressions to get the title from the response text, for example:
var re_title = new RegExp("<title>[\n\r\s]*(.*)[\n\r\s]*</title>", "gmi"); var title = re_title.exec(responseText); if (title) title = title[1]
And to get the content in the keyword meta tag, I need to use some regular expressions.
For the content to be visible to the user, we do not need tags such as script, div, etc. Also, we do not need text between script tags. It is only necessary to get words that make sense in the body of the answer.
I think (as with several stackoverflow posts), using regular expressions to do this is not quite the right approach. What could be an alternative?
source share