We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dcb1458 commit 999fddeCopy full SHA for 999fdde
src/utils/filter.ts
@@ -1,9 +1,10 @@
1
export function matchCharactersWithRegex(word: string, searchTerm: string) {
2
const escapedSearchTerm = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3
4
+ // Construct a regex pattern that enforces order but allows small gaps
5
const regexPattern = escapedSearchTerm
6
.split("")
- .map((char) => `(?=.*${char})`)
7
+ .map((char, index) => (index === 0 ? char : `[^${char}]{0,2}${char}`)) // Allow at most 2 non-matching chars between each
8
.join("");
9
10
const regex = new RegExp(regexPattern, "i"); // 'i' flag for case-insensitive matching
0 commit comments