Fuzzy keyword filtering example

Comma-separated keywords:


To get an idea about how cool this script really is, try typing "old" into the filter field. Try "rod", too. Also note that by typing "band" or "bond" into the filter the "Borland" keyword is found.


Code used to filter the keywords is quite straightforward:

function filterStringArray(input, stringArray) {
var reg = new RegExp(input.replace(/\W/g, '').split('').join('\\w*'), 'i');
  return stringArray.filter(function(element) {
    if (element.match(reg)) {
    return element;

This script's great weakness is its performance. When tested with over 500 keywords, the user experience was jagged and suboptimal. One thing to consider is to cache the compiled regular expressions (or even search results), so repeated searches for the same phrase can run somewhat faster, but I personally don't find it worth the hassle.

Peter Perhac (personal website, [SK])

Peter Perhac (blog on programming [EN])

Big thanks to Dustin Diaz and contributors to his website He originally posted the code I used to create this article. It's not a carbon copy of his code, since I actually had to fix some bugs in it.