Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions _benchmarks/regex-without-lookahead-vs-regex-with-lookahead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Regex without lookahead vs Regex with lookahead
setup: |
const attrs = [
'fa',
'has',
'is',
'fa-',
'has-',
'is-',
'fa-home',
'has-text-centered',
'is-primary',
'orientation',
'data-username',
'aria-hidden'
]

const checkAttribute = (attr, regex) => (new RegExp(regex)).test(attr)
const regexWithoutLookahead = '^(is|has|fa)-.+'
const regexWithLookahead = '^(?=(fa|has|is)-).+'
tests:
-
name: Regex without lookahead
code: |
attrs.forEach(attr => {
const check = attr.trim().toLowerCase()
checkAttribute(check, regexWithoutLookahead)
})
-
name: Regex with lookahead
code: |
attrs.forEach(attr => {
const check = attr.trim().toLowerCase()
checkAttribute(check, regexWithLookahead)
})
---