我将使用什么JavaScript正则表达式来发现一个字符串包含一个打开的HTML标签而不包含一个关闭的HTML标签?

| 我将使用什么JavaScript正则表达式来发现一个字符串包含一个打开的HTML标签而不包含一个关闭的HTML标签。例如如下:
var tags = [\'h1\', \'div\', \'span\']; // tag to look for

var str1 = \'lorem ipsum <h1>hello world\'; // here it is!

var str2 = \'boo foo 123 test\'; // this one doesn\'t have any

var str3 = \'<span>boo-boo</span>\'; // this has the tags but it is not the case as we only need the ones that have open tags and not close tags.
    
已邀请:
您无法使用正则表达式解析HTML。跟踪打开/关闭标签对需要一个堆栈,而一个正则表达式是一个没有堆栈的有限状态机。     
\'(\\<(/?[^\\>]+\\>)\'
此表达式用于HTML标签。     

要回复问题请先登录注册