Check if a string is html or not

I have a certain string for which I want to check if it is a html or not. I am using regex for the same but not getting the proper result.

I validated my regex and it works fine here.

var htmlRegex = new RegExp("<([A-Za-z][A-Za-z0-9]*)\b[^>]*>(.*?)</\1>");
return htmlRegex.test(testString);

Here’s the fiddle but the regex isn’t running in there.

On my machine, the code runs fine but I get a false instead of true as the result.
What am missing here?

88 thoughts on “Check if a string is html or not”

Leave a Comment