From 69fef87cd9465f2d865d3fff603c2543540be705 Mon Sep 17 00:00:00 2001 From: "Felix W. Dekker" Date: Sun, 1 Dec 2019 21:52:04 +0100 Subject: [PATCH] Make filtering optionally case insensitive Fixes #5. --- index.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 4006c4d..015397f 100644 --- a/index.html +++ b/index.html @@ -86,7 +86,11 @@ filterBaseString(baseString) { // Regex from https://stackoverflow.com/a/3561711/ - const regexSafeAlphabet = this.alphabet.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + const alphabet = this.caseSensitive + ? this.alphabet + : this.alphabet.toLowerCase() + this.alphabet.toUpperCase(); + const regexSafeAlphabet = alphabet.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"); + return baseString.replace(new RegExp(`[^${regexSafeAlphabet}]`, "g"), ""); } }