オープニング HTML タグに一致する正規表現を作成しようとしました。
<\w+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)>
私が思いついたものです。RegexPal.comでうまく機能します http://gyazo.com/cef34f653c4a3483a31394330455c0cf しかし、JS(ChromeとNodeの両方)のテキストで使用しようとするとすぐに、これが発生します:http://gyazo.com/0c938ee289c1632f3f576aaccda1f81e
ルールは次のように定義されます。
var Rules = [
new RegExp("<\w+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)/>"),
new RegExp("<\w+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)>"),
new RegExp("</\w+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)>")
];
Content は次のように定義されます。
var Content = "<!DOCTYPE HTML><html><head><title>derp</title></head><body><div class=\"derp\"><!--this is formatted terribly -->derp<br /></div></body></html>";