I want to come up with Regular Expression to return true if the a closed html tag is matched with an open one in specific text that gets passed in JavaScript. If there is an unmatched tag, it should return false;
For example, if the following text is passed <div>Test</div>
it should return true
but if the following text gets passed <div>Test</div><div>Boom
it should return false
I can only get it to match the first div tags to return true with the following expression
var text = <div>Test</div>;
var text2 = <div>Test</div><div>;
var regex = /[^<>]*<(w+)(?:(?:s+w+(?:s*=s*(?:.*?|'.*?'|[^'>s]+))?)+s*|s*)>[^<>]*</1+s*>[^<>]*|[^<>]*<w+(?:(?:s+w+(?:s*=s*(?:.*?|'.*?'|[^'>s]+))?)+s*|s*)/>[^<>]*|<!--.*?-->|^[^<>]+$/;
var match = regex.test(text);
console.log(match); // true
var match = regex.test(text2);
console.log(match2); // still true should be false
How can I fix it so it functions the way I want it to.