user1240679提出了一个问题:Check if a string is html or not,或许与您遇到的问题类似。
回答者zzzzBov给出了该问题的处理方式:
A better regex to use to check if a string is HTML is:
/^/
For example:
/^/.test('') // true
/^/.test('foo bar baz') //true
/^/.test('
fizz buzz
') //trueIn fact, it's so good, that it'll return true for every string passed to it, which is because every string is HTML. Seriously, even if it's poorly formatted or invalid, it's still HTML.
If what you're looking for is the presence of HTML elements, rather than simply any text content, you could use something along the lines of:
//i.test()
It won't help you parse the HTML in any way, but it will certainly flag the string as containing HTML elements.
希望本文对你有帮助,欢迎支持JavaScript中文网