From 996f583d02e4a1cc2217ecf57771663401942f34 Mon Sep 17 00:00:00 2001 From: Postbot Date: Thu, 7 Sep 2017 18:29:32 +0800 Subject: [PATCH] Create _benchmarks/regex-without-lookahead-vs-regex-with-lookahead.md --- ...thout-lookahead-vs-regex-with-lookahead.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 _benchmarks/regex-without-lookahead-vs-regex-with-lookahead.md diff --git a/_benchmarks/regex-without-lookahead-vs-regex-with-lookahead.md b/_benchmarks/regex-without-lookahead-vs-regex-with-lookahead.md new file mode 100644 index 00000000..dd1cab9f --- /dev/null +++ b/_benchmarks/regex-without-lookahead-vs-regex-with-lookahead.md @@ -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) + }) +--- +