HTML split regex (v9)

Revision 9 of this benchmark created on


Setup

const testString = `<strong>title</strong>
einen Farbabstand von Delta E<1 kalibriert und zeigt eine unglaublich realitätsgetreue Darstellung Ihrer Werke.`

Test runner

Ready to run.

Testing in
TestOps/sec
old regex
const regex = /(<\/?[a-z0-3]+(?:\s[^">]*|"[^"]*")*>)/i

testString.split(regex)
ready
limit length (jan)
const regex = /(<\/?[a-z0-3]+(?:|\s*|(?:\s[^"=>]+=\s*"[^"]*"|\s[^"=>]+){0,10})>)/i

testString.split(regex)
ready
more limits & preprocess
// the longest tag is 6 characters (strong), so we can limit that
// to avoid asterisk on whitespace, we can replace all concecutive whitespace with one single space, and then use ? instead.
const regex = /(<\/?[a-z0-3]{2,6}(?:\s[^">]*|"[^"]*")*>)/i

testString
// replace all concecutive spaces with one
.replace(/\ +/g, " ")

.split(regex)
ready

Revisions

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