更新时间:2022-11-14 23:35:38
它是这样的:
> html = "This is HTML<br><style>#a{}</style>This is more HTML.<style>#b{}</style>"
> tags = []
> html.replace(/<.+?>/g, function(match) { tags.push(match); return "" })
"This is HTML#a{}This is more HTML.#b{}"
> tags
["<br>", "<style>", "</style>", "<style>", "</style>"]
(关于正则表达式不适合解析标记语言的强制性通知).
(An obligatory notice about regexes not being suitable for parsing markup languages).