Custom search with regex?

Hi everyone,
I want to be able to take user input, ignore punctuation, and search for one or more terms for matches. I am able to strip off punctuation with regex but searches are not resolving because the underlying knack data has punctuation. More often than not, users don’t include punctuation and therefore matches aren’t found. As an example, our data is: “Amon G. Carter Foundation”. Users type in things like “Amon Carter” or Amon G Carter" or “Amon G. Carter” or “Carter Foundation”. What is the best way to get this to match, regardless of the combinations a user might type in? Another example, our data is: “B. W. Bastain”, users typically type in “BW Bastain” and there’s no match. On single words, if they type “Bastain” that would work but more than one word is failing to match and that’s typically how the users enter search criteria. Any hints on the best solution for this type of search? Thank you, Carolyn V.

1 Like


You could dynamically add filters (allowing you to run multiple queries) and then hide them with CSS.

Here’s a demo; it successfully returns results for the following searches:

amon carter
amon g carter
amon g. carter
carter foundation
bw bastian
b.w. bastian

For the purposes of this demo, the filters are kept visible so you can see what’s happening.

When the user types “BW Bastian”, instead of submitting a keyword search, filters are created for “B.W. Bastian” or “BW Bastian”. The same logic is applied when someone types “Amon G Carter” and so on.


This works great, but because the keyword search is ignored (it has to be ignored or else the search won’t return the results you want), the reset button does not display; however as a workaround, you can easily add a new reset button.

Another thing to consider is ranking of results. A perfect match should rank higher than a “fuzzy” match. Ideally you would assign a relevance score to each result and rank them by relevance. But that’s a whole other rabbit hole.

To handle all of the above, and create a really amazing search experience, you can integrate Algolia with Knack. To those who aren’t familiar with Algolia, it’s a set of APIs and UI elements to create modern search experiences e.g. autocomplete and predictive search, typo tolerance, relevance, etc.

Keep me updated on which approach you decide to take. It would make a good “Show and Tell” post.

Knack Pros

Hi! I’m interested in integrating Algolia with Knack but can’t seem to find any documentation on the steps to do so. Any suggestions? I’ve already built the database through Knack so would like to somehow add the Algolia search functionalities to allow users to generate better search results (ignore punctuation, etc.). Thanks!


It’s a 3-step process:

  1. Import your data from Knack to Algolia
  2. Configure the “relevance” settings in Algolia
  3. Implement the search UI/UX using one of Algolia’s front-end API clients

Algolia offers a Getting Started guide which covers everything.

You’ll need programming knowledge, ideally JavaScript.