HTML parsing regex

Benchmark created on


Setup

const example = `<dl><dt>foo</dt><dd>bar<i class="icon"/></dd><dt>baz</dt><dd>qux</dd></dl>`

Test runner

Ready to run.

Testing in
TestOps/sec
Original
example.match(/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?([^>]*)\/{0}>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/i)
ready
Proposed
example.match(/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?((?:[^>]*[^/])?)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/i)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.